我写了一个模板类,但它只适用于int
,double
,并不适用于我自己的类。代码如下:
/*OrderedList.h*/
namespace MYLIB
{
class Student
{
public:
display();
private:
char* snum;
char* name;
char* email;
};
template<class T>
class OrderedList
{
public:
OrderedList() :head(), tail(), size(0) {}
~OrderedList(){}
private:
......
};
}
/*main.cpp*/
#include "OrderedList.h"
int main()
{
MYLIB::OrderedList<int> listi;
MYLIB::OrderedList<double> listd;
MYLIB::OrderedList<Student> lists;
}
我收到的错误消息是:'Error: Student is not defined.'
感谢您的帮助。
答案 0 :(得分:6)
Student
在MYLIB
命名空间中定义,就像类模板OrderedList
一样。所以你需要
MYLIB::OrderedList<MYLIB::Student>