I have a class whose functionality I'd like to depend on a set of plug-in policies. But, I'm not sure how to get a class to derive from an arbitrary number of classes.
The code below is an example of what I'm trying to achieve.
// insert clever boost or template trickery here
template< class ListOfPolicies >
class CMyClass : public ListOfPolicies
{
public:
CMyClass()
{
// identifiers should be the result of OR-ing all
// of the MY_IDENTIFIERS in the TypeList.
DWORD identifiers;
DoSomeInitialization( ..., identifiers, ... );
}
int MyFunction()
{
return 100;
}
// ...
};
template< class T >
class PolicyA
{
public:
enum { MY_IDENTIFIER = 0x00000001 };
int DoSomethingA()
{
T* pT = static_cast< T* >( this );
return pT->MyFunction() + 1;
};
// ...
};
template< class T >
class PolicyB
{
public:
enum { MY_IDENTIFIER = 0x00000010 };
int DoSomethingB()
{
T* pT = static_cast< T* >( this );
return pT->MyFunction() + 2;
};
// ...
};
int _tmain(int argc, _TCHAR* argv[])
{
CMyClass< PolicyA > A;
assert( A.DoSomethingA() == 101 );
CMyClass< PolicyA, PolicyB > AB
assert( AB.DoSomethingA() == 101 );
assert( AB.DoSomethingB() == 102 );
return 0;
}
Thanks, PaulH