不允许在数据声明中使用“friend”的错误
代码如下:
class Integer
{
long left;
long right;
public:
Integer(int l, int r):left(l),right(r){}
friend ostream& operator<<(ostream& ,const Integer);
};
ostream& operator<<(ostream& cout,const Integer integer)
{
cout<<integer.left<<"."<<integer.right;
return cout;
}
运行这段代码总是出错
error C2143: 语法错误 : 缺少“;”(在“&”的前面)
“ostream”: 不允许在数据声明中使用“friend”
。。。
请教为什么
class Integer
{
long left;
long right;
public:
Integer(int l, int r):left(l),right(r){}
friend ostream& operator<<(ostream& ,const Integer);
};
ostream& operator<<(ostream& cout,const Integer integer)
{
cout<<integer.left<<"."<<integer.right;
return cout;
}
运行这段代码总是出错
error C2143: 语法错误 : 缺少“;”(在“&”的前面)
“ostream”: 不允许在数据声明中使用“friend”
。。。
请教为什么
...全文
相关推荐
C++.pdf
。
解决"XML Parser Error on line 1: 前言中不允许有内容"错误
解决用windows自带的记事编辑xml文件后出现 "XML Parser Error on line 1: 前言中不允许有内容。"的错误
http请求405错误方法不被允许的解决 (Method not allowed)
主要介绍了http请求405错误方法不被允许的解决 (Method not allowed),文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
C++中的friend友元函数详细解析
友元可以是一个函数,该函数被称为友元函数;友元也可以是一个类,该类被称为友元类。友元函数的特点是能够访问类中的私有成员的非成员函数。友元函数从语法上看,它与普通函数一样,即在定义上和调用上与普通函数一样
易语言不声明使用API源码
易语言不声明使用API源码。@易语言入门教程。


