定义这么个模板类:
#include
using namespace std;
template
class List
{
public:
List(int MaxSize = 10);
virtual~List();
bool IsEmpty() const { return(length == 0); }
int Length() const { return length; }
bool Find(int k, T & x) const;
int Search(const T & x) const;
List& Insert(int k, const T & x);
List& Delete(int k, T & x);
void show();
private:
int length;
int MaxSize;
T *element; // 一维动态数组
};
其中:
template
void List::show(){
for (int i = 0; i < length; i++){
cout << element[i] << endl;
}
}
main函数:
void main(){
List MyList(5);
cout << "IsEmpty: " << MyList.IsEmpty() << endl;
cout << "Length: " << MyList.Length() << endl;
MyList.Insert(0, 1).Insert(1, 2).Insert(2, 3).Insert(3, 4);
cout << "MyList is: " << MyList.show() << endl;
}
然后 cout << "MyList is: " << MyList.show() << endl; 这条语句会出错,错误指向 MyList.show() 前面的<< 这个符号,请问是怎么回事???