I try to achieve the following behavior/syntax/usage of this class:
Data1 dataType1;
Data2 dataType2;
int intType;
float floatType;
dataType1.method( intType );
dataType1.method( floatType );
dataType2.method( intType );
dataType2.method( floatType );
My approach would be this:
struct CDataBase
{
template< typename T > virtual void method( T type ) = 0;
};
struct CData1 : CDataBase
{
template< typename T > void method( T type ) {}
};
struct CData2 : CDataBase
{
template< typename T > void method( T type ) {}
};
However virtual template methods aren't possible. Also there is no need for an actual base class, However I have to ensure that some classes got a (template) 'method()' implemented.
How do I force a non-templated class/struct to override a template method?
EDIT: This is my actual layout:
struct Data0
{
int someVar;
template< class T >
void decode( T& type )
{
type.set( someVar );
}
};
EDIT: in the current version of C++ (11) the behavoir I try to achieve isn't possible. In addition to that, I should really recode this part to avoid this problem. However I accept the only answer given, thanks for you affort.