//Complex class member-function definitions
#include "stdafx.h"
#include "iostream"
using std::cout;
using std::cin;
using std::endl;
#include "Complex.h"
Complex::Complex(float r, float i)
{
real=r;
imagine=i;
}
void Complex::input()
{
cout<<endl;
cout<<"Enter real part: ";
cin>>real;
cout<<"Enter imaginary part: ";
cin>>imagine;
}
void Complex::print()
{
cout<<"Your complex number"<<endl;
cout<<real<<" + "<<imagine<<"i"<<endl;
}
Main program
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
//Main program
#include "stdafx.h"
#include "iostream"
using std::cout;
using std::cin;
using std::endl;
#include "Complex.h"
int main()
{
Complex a;
a.input();
a.print();
return 0;
}
When I press Ctrl + F5 for debug, some errors occured
1 2
1>1-Complex.obj : error LNK2019: unresolved external symbol "public: __thiscall Complex::Complex(void)" (??0Complex@@QAE@XZ) referenced in function _main
1>D:\Study\Tran Van Tuan\University\Subjects\OOP\Thuc Hanh OOP\Projects\1\1-Complex\Debug\1-Complex.exe : fatal error LNK1120: 1 unresolved externals
When I turn on the "Display all progress message" in Project Properties > Linker > General > Show Progress, the error was here
As far as I know you shouldn't include the precompiled header in another header. Since precompiled header are useless I'd suggest to switch them off.
But that's not the point. The point is that you haven't implemented the constructor the compiler is complaining about. In 'Complex.cpp' there should be something like this: