未定义标识符
边卓琳 2019-11-05 05:52:21 #ifndef _COMPLEX_
#define _COMPLEX_
class complex
{
public:
complex(double r = 0, double i = 0)
: re(r), im(i)//initialization line初始值列
{}
complex& operator += (const complex&);
double real() const { return re; }//const 不变的量
double imag() const { return im; }
private://私有的,不想让其他函数调用
double re, im;
friend complex& _doapl(complex*, const complex&);//友元可以调用内部数据
};
//成员函数
inline complex&
_doapl(complex* ths, const complex& r)//ths是一个指针
{
ths->re += r.re;
ths->im += r.im;
return *ths;//返回的是指针所代表的值
}
inline complex&//接口部分
complex::operator +=(const complex& r)
{
return _doapl(this, r);
}
//非成员(全局)函数
//操作符重载
inline complex//下面一定是一个临时(本地)变量不能返回引用
operator + (const complex& x, const complex& y)
{
return complex(real(x) + real(y), imag(x) + imag(y));
}
inline complex
operator +(const complex& x, double y)
{
return complex(real(x) + y, imag(x));
}
inline complex
operator +(double x, const complex& y)
{
return complex(x + real(y), imag(y));
}
#include <iostream>
using namespace std;
ostream&
operator << (ostream& os, const complex& x)
{
return os << '(' << real(x) << ',' << imag(x) << ')';
#endif // !_COMPLEX_
}
显示real,imag未定义标识符
可我是从标准库中摘下来的,不知道哪出问题了