运算符>>重载为类的友元出错
头文件array:
class CArray{
public:
CArray(int n = 20);
CArray(CArray&);//拷贝构造函数
~CArray();
int getsize() const;//返回数组长度
const CArray &operator = (const CArray&);//重载赋值运算符=
bool operator == (const CArray&) const;//重载==
bool operator != (const CArray&) const;//重载!=
int &operator [] (int) const;//重载[]
friend istream &operator >> (istream&, const CArray&);//重载>>
friend ostream &operator << (ostream&, const CArray&);//重载<<
private:
int size;//数组长度
int *aptr;//指向数组首元素的指针
};
1>e:\ccode\text\array\array\array.h(11): error C2143: 语法错误 : 缺少“;”(在“&”的前面)
1>e:\ccode\text\array\array\array.h(11): error C2433: “istream”: 不允许在数据声明中使用“friend”
1>e:\ccode\text\array\array\array.h(11): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\ccode\text\array\array\array.h(11): error C2061: 语法错误: 标识符“istream”
1>e:\ccode\text\array\array\array.h(11): error C2805: 二进制“operator >>”的参数太少
1>e:\ccode\text\array\array\array.h(12): error C2143: 语法错误 : 缺少“;”(在“&”的前面)
1>e:\ccode\text\array\array\array.h(12): error C2433: “ostream”: 不允许在数据声明中使用“friend”
1>e:\ccode\text\array\array\array.h(12): error C4430: 缺少类型说明符 - 假定为 int。注意: C++ 不支持默认 int
1>e:\ccode\text\array\array\array.h(12): error C2061: 语法错误: 标识符“ostream”
1>e:\ccode\text\array\array\array.h(12): error C2805: 二进制“operator <<”的参数太少
1>e:\ccode\text\array\array\arraymain.cpp(9): error C2679: 二进制“>>”: 没有找到接受“CArray”类型的右操作数的运算符(或没有可接受的转换)