Sorry for such a not good title. Now please see my detailed question.
Actually, I faced with such an exercise problem: Definite a class CComplex
for complex number. Then, definite two objects c1
and c2
in CComplex
. Next, use a constructor to initialize c1
and c2
. After that, give c1
's value to c2
.
My code is as followed:
#include<iostream>
using namespace std;
class CComplex
{
public:
CComplex(int real1,int image1)
{
real=real1;
image=image1;
}
CComplex(CComplex &c)
{
real=c.real;
image=c.image;
}
public:
void Display(void)
{
cout<<real<<"+"<<image<<"i"<<endl;
}
private:
int real,image;
};
int main()
{
CComplex c1(10,20);
CComplex c2(0,0);
c1.Display();
c2.Display();
CComplex c2(c1);
c2.Display();
return 0;
}
It has an error that 'c2' : redefinition
.
Then, I changed CComplex c2(c1);
into c2(c1);
.
At this time, it has an error that error C2064: term does not evaluate to a function
Now, I don't know how to correct it.
PS: I know that using c2=c1
can achieve the goal straightly. But, I really want to know how to correct almost based on my code above. Also, I want to know if there is any better ways to convey a complex number.