【发布时间】:2019-12-22 08:20:01
【问题描述】:
我不知道用模板编写类函数定义的语法。
我得到一个错误,编译器预期; ,所以是 无效加; 任何人都知道要解决这个问题!
template<class Type
class basic{
protected:
Type x;
public:
int value;
//virtual void print() =0;
basic(Type xArg):x(xArg){}
};
template<class Type>
class plus:public basic<Type>{
public:
Type y;
plus(Type xArg, Type yArg):basic<Type>(xArg),y(yArg){}
void print();
};
//template<class Type>
void plus<Type>::print(){
cout << "x : " << x << endl;
cout << "y : " << y << endl;
}
【问题讨论】:
-
如果取消注释
//template<class Type>行会发生什么? -
在此感谢您:)
-
问题依旧,解决不了
-
你提到的错误对我来说似乎不存在:godbolt.org/z/T8K08a
-
template<class Type你只是忘了结束>
标签: c++ templates inheritance virtual