新手求指教
#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(){}。