I have declared a class below is header file:
class Complex
{
private:
int real;
int imaginary;
public:
Complex(); // no arg contructor
Complex(int,int); // 2 - args constructor
Complex(const Complex& temp); // copy constructor
};
No I am trying to declare copy constructor again,I know it works but wanted to have some more functionality but its not working when I am including its code in implementation file.Here is code from implementation file.
Compelx::Complex(const Complex& temp) // copy constructor
{
real = 2*temp.real;
imaginary =2*temp.imaginary;
}
In the main()
I have following code
Complex a,b;
a.setReal(10);
cout<<a.getReal()<<endl;
b=a; // problem is here, copy constructor(that is redefined one) is not being executed.
b.print();
Copy constructor is not executing instead I am getting following error:
1> Complex.cpp 1>Complex.cpp(21): error C2653: 'Compelx' : is not a class or namespace name 1>Complex.cpp(21): error C2226: syntax error : unexpected type 'Complex' 1>Complex.cpp(22): error C2143: syntax error : missing ';' before '{' 1>Complex.cpp(22): error C2447: '{' : missing function header (old-style formal list?) 1> main.cpp 1> Generating Code... ========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========