Given the code below, the compiler is showing a message pointing that error: templates may not be ‘virtual’
. Does anyone have a suggestion on how to solve the bug?<
You can use what we call in Symbian as "template design pattern". Here is sample code to give you an idea:
class Base {
public:
virtual int DoSomething() = 0;
protected:
Base();
};
class IntermediateBase : public Base {
protected:
IntermediateBase(void* aSomeParam, void* aArg)
: iSomeParam(aSomeParam)
, iArgs(aArg)
{}
virtual int DoSomething() = 0;
protected:
void* iSomeParam;
void* iArgs;
};
template
class ConcreteClass : public IntermediateBase {
typedef int (TYPE::*MemberFuncPtr)(const INPUT&);
public:
ConcreteClass(TYPE& aCommandType,
INPUT& aArgumentsToCommand,
MemberFuncPtr aMFP)
: IntermediateBase(static_cast(&aCommandType),
static_cast(&aArgumentsToCommand) )
, iMFP(aMFP)
{}
virtual int DoSomething() // VIRTUAL AND INLINE Note - dont make it
// virtual and inline in production if
// possible to avoid out-of-line copy
{
return static_cast(iSomeParam)->*ConcreteClass::iMFP)
(*(static_cast(iArgs));
}
private:
MemberFuncPtr iMFP;
};