I’m trying to write an templated class with some methods/operators etc.. Now when the class is of an specififc type i would like to have extra append methods specially suited for that type which arent there for any other type. I dont’ want to copy all the code into an new class.
Example:
template<typename T>
class Buffer
{
Buffer(const Buffer<Type> &Buffer) : mData(Buffer.mData)
{
}
Buffer<Type> Clone()
{
}
void Append (T * aData)
{
}
// this one should only be there when Type is an unsigned char
void Append (wchar_t * aData)
{
}
}
is this at all possible?
Greetz,
Richard.
Use a policy class to manage the interaction with the type, then your class doesn’t really have to worry about the type that is passed in, an appropriate policy (and specialization of said policy) can contain all the logic specific to that type.
EDIT: now allows you to append any type to any type of
MyClass, and allows you to override specific combination of types, and potentially throw exceptions in other combinations which you don’t want to support.