~complexNumber(){cout<<"Destructor do it's work..!"<<endl;}
double get_real(){return realPart;}
double get_imaginary(){return imaginaryPart;}
void set_real(double r){realPart=r;}
void set_imaginary(double i){imaginaryPart=i;}
complexNumber operator+(const complexNumber& c);
complexNumber operator-(const complexNumber& c);
};
void main()
{
complexNumber c1,c2,c3;
c1.set_real(3.4);
c1.set_imaginary(4.5);
c2.set_real(5.6);
c2.set_imaginary(6.2);
c3= c1 + c2;
cout<< c1 <<endl<< c2 <<endl<< c3 <<endl;
}
i wrote that code according to some topics in this forum but it gives me a error
Quote ...
error C2679: binary '<<' : no operator defined which takes a right-hand operand of type 'class complexNumber' (or there is no acceptable conversion)
How can i fix this?
Also i have to write a display function to print complex numbers according to my code i can not do it please also help me in this problem...
Have a good day...
P.S. i have just registered yet sorry if i did sth wrong...:rolleyes:
~complexNumber(){cout<<"Destructor do it's work..!"<<endl;}
double get_real(){return realPart;}
double get_imaginary(){return imaginaryPart;}
void set_real(double r){realPart=r;}
void set_imaginary(double i){imaginaryPart=i;}
complexNumber operator+(const complexNumber& c);
complexNumber operator-(const complexNumber& c);
};
void main()
{
complexNumber c1,c2,c3;
c1.set_real(3.4);
c1.set_imaginary(4.5);
c2.set_real(5.6);
c2.set_imaginary(6.2);
c3= c1 + c2;
cout<< c1 <<endl<< c2 <<endl<< c3 <<endl;
}
i wrote that code according to some topics in this forum but it gives me a error
How can i fix this?
Also i have to write a display function to print complex numbers according to my code i can not do it please also help me in this problem...
Have a good day...
P.S. i have just registered yet sorry if i did sth wrong...:rolleyes:
You haven't defined the methods for operator overloading so what do you expect. Miracles?
The method for overloading the << operator is slightly different. You have to be careful when doing that.
i have looked that topic but i couldn't get the main idea of overloading "<<" operator...
Can you give me a little code for cout complexNumbers from my code???
This code is working but can not print my complex numbers...
Can you edit this code's "<<" operator for me???or give me an idea please...
Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.
This thread is more than three months old
No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Previous Thread in C++ Forum Timeline:Please Help!