求错误讲解,最好给个答案
#include<iostream>using namespace std;
class complex
{ public:
int real,image;
complex(int a=0,int b=0)
{ real=a;
image=b;
cout<<real<<"+"<<image<<"i";
}
~complex();
friend complex & operator*(complex &x,complex &y);
complex & operator/(complex &n);
friend ostream & operator<<(ostream &outpyt,complex &v);
};
complex & complex::operator/(complex &n)
{ complex t;
t.real=(real*n.real+image*n.image)/(n.real*n.real+n.image*n.image);
t.image=(image*n.real-real*n.image)/(n.real*n.real+n.image*n.image);
return t;
}
complex & operator*(complex &x,complex &y)
{ complex z;
z.real=(x.real*y.real)-(x.image*y.image);
z.image=(x.real*y.image)+(x.image*y.real);
return z;
}
ostream & operator<<(ostream &output,complex &v)
{ output<<v<<' ';
return output;
}
void main()
{ complex x(1,2),y(1,3),z(),c();
z()=operator*(x,y);
c()=x.operator/(y);
cout<<x<<' '<<y<<' '<<z<<' '<<c<<endl;
}
1>c:\users\tel\documents\visual studio 2012\projects\consoleapplication15\consoleapplication15\源.cpp(22): warning C4172: 返回局部变量或临时变量的地址
1>c:\users\tel\documents\visual studio 2012\projects\consoleapplication15\consoleapplication15\源.cpp(28): warning C4172: 返回局部变量或临时变量的地址
1>c:\users\tel\documents\visual studio 2012\projects\consoleapplication15\consoleapplication15\源.cpp(33): warning C4717: “operator<<”: 如递归所有控件路径,函数将导致运行时堆栈溢出
1>源.obj : error LNK2019: 无法解析的外部符号 "public: __thiscall complex::~complex(void)" (??1complex@@QAE@XZ),该符号在函数 "class complex & __cdecl operator*(class complex &,class complex &)" (??D@YAAAVcomplex@@AAV0@0@Z) 中被引用
1>C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.CppCommon.targets(611,5): error MSB6006: “link.exe”已退出,代码为 1120。
1>源.obj : error LNK2019: 无法解析的外部符号 "class complex __cdecl z(void)" (?z@@YA?AVcomplex@@XZ),该符号在函数 _main 中被引用
1>源.obj : error LNK2019: 无法解析的外部符号 "class complex __cdecl c(void)" (?c@@YA?AVcomplex@@XZ),该符号在函数 _main 中被引用
1>c:\users\tel\documents\visual studio 2012\Projects\ConsoleApplication15\Debug\ConsoleApplication15.exe : fatal error LNK1120: 3 个无法解析的外部命令
[ 本帖最后由 APTX 于 2015-3-30 13:23 编辑 ]