This may be a novice question, but I can't figure it out by inspecting the book I have. The class's constructor initializes two doubles, and I want the following code to output those two doubles with <<.
Complex x( 3.3, 1.1 );
cout << "x: " << x;
After this I need to overload >> to accept two doubles into these. This is my first question here, so if my information provided is lacking inform me
EDIT: I now have for the constructor and overloading statement this:
#include "Complex.h"
Complex::Complex( double realPart, double imaginaryPart )
: real( realPart ),
imaginary( imaginaryPart )
{
}
std::istream& operator>>(std::istream& strm, const Complex &c)
{
double r,i;
strm >> r >> i;
c = Complex(r,i);
return strm;
}
I know I have to change the "const Complex &c" and the "c = Complex(r,i);" but I'm not sure how to go about it. Also, I will say here that this is not about the std library's Complex class, although it is based on the same idea. So far everyone has been a great help, but I have a case of the dumb today.