我正在实现多态协议处理程序,并且在我的基类中我想要一个纯虚函数,其中未指定模板函数参数。但是我的编译器在抱怨。我想这是做不到的。有人对如何实现这一目标有任何建议吗?如果可能的话?否则我将不得不放弃多态的想法。
这是我的代码,它给了我错误 C2976 'ProtoWrapper':模板参数太少。编译器=MSVC++2008。
#include "smartptrs.hpp"
#include <iostream>
class realproto {
public:
   const char* getName() const { return "realproto"; }
}; 
class real2ndproto {
public:
   const char* get2Name() const { return "real2ndproto"; }
}; 
template<typename T>
class ProtoWrapper : public ref_type {
public:
   ProtoWrapper(T* real) : m_msg(real) {}
   ~ProtoWrapper() { delete m_msg; }  //cannot have smart ptr on real_proto - so do this way
   T* getMsg() { return m_msg; }
private:
   T* m_msg;
};
class ProtocolDecoder 
{
public:
  virtual void Parse(ProtoWrapper<>* decoded_msg) = 0;  //problem line - compile error
};
class CSTA2Decoder  : public ProtocolDecoder
{
public:
   virtual void Parse(ProtoWrapper<realproto>* decoded_msg) {
      realproto* pr = decoded_msg->getMsg();
      std::cout << pr->getName() << std::endl;
   }
};
int main(int argc, char* argv[])
{
   {
      ref_ptr<ProtoWrapper <realproto> > msg2 = new ProtoWrapper<realproto>(new realproto);
      realproto* pr1 = msg2->getMsg();
      std::cout << "created new realproto\n";
   } 
    return 0;
}