rwf_20 wrote:
> I just wanted to throw this up here in case anyone smarter than me has
> a suggestion/workaround:
>
I don't know whether I'm smarter, thats (smarter in terms of what)...
but
You need to abstract dynamic and static polymorphism from each other.
You want to be able to use dynamic polymorphism to execute via one
interface, but static polymorphism to call something specific (I don't
know whether this makes sense).
You can never bind the sender of your command to a receiver type, as it
may want to send msgs to arbitrary receivers. For this reason, your
base should use dynamic polymorphism (I'll be brief).
struct BaseCmd
{
void execute() = 0;
BaseCmd* clone() const = 0; //I know of better clone implementations

};
class Client //Going to call Cmd.execute
{
void associate( const BaseCmd& cmd ){ cmd_ = cmd.clone(); }
//...
BaseCmd* cmd_;
};
template <class T>
class MyCmd : public BaseCmd
{
//Implements execute.
};
Now we win by creating 1 command that represents all type T's, but
Client is oblivious as the BaseCmd is not type dependent. Winning both
ways by abstracting dynamic and static parts.
For more information, you can also refer to Herb Sutters article
"Elegant function call wrappers".
Kind regards,
Werner