0

我在模板继承方面遇到了一个小问题。

如果我使用模板创建接口类:

template<typename Data>   
class InterfaceClass {
   private:
   public:
      virtual Data* foo() = 0; //some function that returns our template type
}

然后我创建了一个实现:

template<typename MoData>
class Implementation : public InterfaceClass<MoData> {
   private:
   public:
      MoData* foo() { MoData* ptr = NULL; return ptr; } //some implementation
}

我似乎在我的编译器中遇到了这个问题。这不合法吗?

4

3 回答 3

3
template<typedef Data>

是不正确的。

你应该使用

template<class Data>

或者

template<typename Data> 
于 2013-09-19T06:17:02.060 回答
1
template <typedef Data>

错了,用

template <typename Data>   
于 2013-09-19T06:17:10.963 回答
0

Please add semicolon at the end of class declaration.

template<typename Data>   
class InterfaceClass {
   private:
   public:
      virtual Data* foo() = 0; //some function that returns our template type
};
于 2013-09-19T06:25:58.287 回答