为什么编译有错误,一个重载函数为友元函数时。显示类中声明为友元函数那编译错误
#include<iostream>usingnamespacestd;classComplex{public:Complex(doubler,doublei):real...
#include<iostream>
using namespace std;
class Complex
{
public:
Complex(double r,double i):real(r),imag(i){}
friend Complex operator + (Complex &,Complex &);
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
int main()
{
return 0;
} 展开
using namespace std;
class Complex
{
public:
Complex(double r,double i):real(r),imag(i){}
friend Complex operator + (Complex &,Complex &);
private:
double real;
double imag;
};
Complex operator + (Complex &c1,Complex &c2)
{
return Complex(c1.real+c2.real,c1.imag+c2.imag);
}
int main()
{
return 0;
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询