|
|
马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 刹那芳华 于 2013-9-6 10:00 编辑
- #include <iostream>
- #include "StdAfx.h"
- using namespace std;
- template <class T>
- class SeqList
- {
- private:
- T *element;
- int size;
- int len;
- public:
- SeqList(int size = 64);
- SeqList(T value[],int n);
- ~SeqList();
- bool isEmpty();
- int length();
- T get(int i);
- bool set(int i,T x);
- friend ostream& operator<<(ostream& out,SeqList<T> &list);
- void insert(int i,T x);
- void insert(T x);
- bool remove(int i,T& old);
- void clear();
- };
- template <class T>
- ostream& operator<<(ostream& out,SeqList<T> &list)
- {
- out<<"(";
- if(list.len>0)
- {
- out<<list.element[0];
- for(int i = 1;i<list.len;i++)
- out<<","<<list.element[i];
- }
- out<<")\n";
- return out;
- }
复制代码 在vs2010里面,友元函数重载运算符老是通不过
将指令添加到“StdAfx.h”或重新生成预编译头
1>SeqList.h(20): error C2143: 语法错误 : 缺少“;”(在“&”的前面)
1> SeqList.h(25): 参见对正在编译的类 模板 实例化“SeqList<T>”的引用
1>SeqList.h(20): error C2433: “ostream”: 不允许在数据声明中使用“friend”
1>SeqList.h(20): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>SeqList.h(20): error C2061: 语法错误: 标识符“ostream”
1>SeqList.h(20): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>SeqList.h(20): error C2805: 二进制“operator <<”的参数太少
1>SeqList.h(78): error C2143: 语法错误 : 缺少“;”(在“&”的前面)
1>SeqList.h(78): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>SeqList.h(78): error C2086: “int ostream”: 重定义
1> SeqList.h(20) : 参见“ostream”的声明
1>SeqList.h(78): error C2065: “out”: 未声明的标识符
1>SeqList.h(78): error C2065: “T”: 未声明的标识符
1>SeqList.h(78): error C2955: “SeqList”: 使用类 模板 需要 模板 参数列表
1> SeqList.h(7) : 参见“SeqList”的声明
1>SeqList.h(78): error C2065: “list”: 未声明的标识符
|
|