首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > C++ >

生手求指教

2012-09-05 
新手求指教#includeiostreamusing namespace stdclass Complex{public:Complex()Complex(double r,dou

新手求指教
#include<iostream>
using namespace std;
class Complex
{
public:
Complex();
Complex(double r,double i):real(r),imag(i){}
void display();
double real;
double imag;
};
Complex operator + (Complex a,Complex b)
{
Complex c;
c.real=a.real+b.real;
c.imag=a.imag+b.imag;
return c;
}
void Complex::display()
{
cout<<"("<<real<<","<<imag<<"i)"<<endl;
}
int main()
{
Complex a(1,2);
Complex b(3,4);
Complex c;
c=a+b;
c.display();
return 0;
}
这个程序有什么问题吗?为什么总是在build的时候出现两个errors:
Linking...
af.obj : error LNK2001: unresolved external symbol "public: __thiscall Complex::Complex(void)" (??0Complex@@QAE@XZ)
Debug/af.exe : fatal error LNK1120: 1 unresolved externals
Error executing link.exe.

[解决办法]
你没有实现Complex(),可以这样Complex(){}。

热点排行