【发布时间】:2018-11-29 03:47:43
【问题描述】:
我收到以下错误:
..\src\test.cpp:17:20: error: expected unqualified-id before 'try'
friend int try(Complex);
请帮助并告诉我为什么这段代码会产生错误:
#include <iostream>
using namespace std;
class Complex
{
private:
int a, b;
public:
showData()
{
cout<<"\na= "<<a<<" b= "<<b;
}
Complex(int x, int y)
{ //constructer
a = x;
b = y;
}
friend int try(Complex);
//friend function
};
int try(Complex c)
{
cout<<"You areworking in try now";
cout<<"\noutput from friend fun : "<<c.a<<" "<<c.b;
}
int main()
{
Complex c1(3, 4);
try(c1);
return 0;
}
【问题讨论】:
-
请使用tour,访问help center,阅读How to Ask以及如何创建minimal reproducible example。最重要的是,代码和错误消息都是文本,因此请照此发布。没有图片,也没有任何图片链接。复制和粘贴内容比抓取屏幕截图并上传要省力。它还使您的问题可搜索。
-
我强烈建议不要发布图片。它们很难搜索,也更难编译。除非图片真的值一千字,或者问题是关于像素的,否则不要使用它们。
-
我建议您也阅读idownvotedbecau.se 中的原因列表。其中一些与您的帖子有关,可以帮助您在未来提出更好的问题。
标签: c++ compiler-errors friend