The class HandleMessages below has a member variable of type ProtocolDecoder*. This was fine when ProtocolDecoder was not a template class. Now I have changed to be so, but now code won't compile.
At runtime there is a factory function which creates the required decoder.
If I can't have a member m_Decoder then how can I achieve the same effect?
If I try to declare the member as ProtocolDecoder* m_Decoder;
I get compiler error: error C2059: syntax error : '<'
and see reference to class template instantiation 'LogPlayer' being compiled
template <typename T>
class ProtocolDecoder
{
public:
virtual const char* ProtocolName() = 0;
virtual ProtoWrapper<T>* DecodeMsg(const unsigned char* msg, int length) = 0;
...
};
class ABCDecoder : public ProtocolDecoder<ABC_msg>
{
public:
virtual const char* ProtocolName() {return "ABC"; }
virtual ProtoWrapper<ABC_msg>* DecodeMsg(const unsigned char* msg, int length);
};
//lots of different decoders derived from ProtocolHandler
class HandleMessages
{
public:
void Process() {}
private:
//ProtocolDecoder<T>* m_Decoder; //Want a Protocol member variable - but don't know type until runtime
};