[英]C++ implement generic class
I am trying to create a generic class in C++ but I am getting the error "expected constructor, destructor, or type conversion before '<' token " on lines 6, 16, 19... 我正在尝试在C ++中创建一个通用类,但是在第6、16、19行上出现了“在'<'令牌之前的预期构造函数,析构函数或类型转换”的错误。
I am just creating a simple class and pretty sure I can go on from there. 我只是在创建一个简单的类,并且很确定我可以从那里继续。 Here is the sample code I am dealing with: 这是我正在处理的示例代码:
using namespace std;
//line 6
generic < class T>
class Table
{
friend class Table;
Table< T> *LT;
LT_Node* cursor;
public:
Table();
~Table();
Table(const Table & source);
Table& operator =(const Table& rhs);
};
//line 16
generic < class T>
Table< T>::Table(){}
//line 19
generic < class T>
Table< T>::~Table(){}
generic < class T>
Table< T>::Table(const Table & source){}
generic < class T>
Table::Table& operator =(const Table& rhs){}
Thanks in advance! 提前致谢!
If this is ordinary C++ the keyword isn't generic
but template
. 如果这是普通的C ++,则关键字不是generic
关键字,而是template
。 You are defining a template for a class or function, that is later instantiated when used. 您正在为类或函数定义模板,该模板或函数将在以后使用时实例化。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.