简单的c++改错

来源:百度知道 编辑:UC知道 时间:2024/06/07 21:33:24
#include <iostream.h>
#include "dataList.h"
const int SZ = 10;
int main ( )
{
struct sick { //患者
int key;
char *name[15];
int age;
char *address[30];
bool operator < (sick x) { return key < x.key; }
}ee;
dataList <int,sick> TestList (SZ);
cin >> TestList;
cout << TestList << endl;
TestList.sort ( );
cout << TestList << endl;
return 0;
}
错误是'struct main::sick' : types with no linkage cannot be used as template arguments

下面是头文件
#ifndef DATALIST_H
#define DATALIST_H
#include <iostream.h> //K是表项关键码类型
template <class K,class E> //E是表项类型
class dataList {
private:
E *element;
int listSize;
void swap (int m1,

在主函数里定义的 sick结构体,编译器在用类模板实例类时,并不知道 sick是一种什么类型.于是返回了没有sick这种类型的错误.
解决办法:
将sick的声明或定义放在头文件中,要在类模板的前面.

而且对结构体来说,一些远算符要重载,如>>等.