C

#### Colonel

istream operator ">>", but I just can't find the exact problem.

// the declaration

friend std::istream & operator>> (std::istream & in, const Complex & a);

// the methods correspond to the friend

std::istream & operator>> (std::istream & in, const Complex & a)

{

std::cout << "real: ";

in >> a.real;

std::cout << "imaginary: ";

in >> a.imaginary;

return in;

}

When complex0.cpp was compiled, such problem appeared:

Compiling...

complex0.cpp

D:\C++\complex\complex0.cpp(45) : error C2679: binary '>>' : no operator

defined which takes a right-hand operand of type 'const double' (or there is

no acceptable conversion)

D:\C++\complex\complex0.cpp(47) : error C2679: binary '>>' : no operator

defined which takes a right-hand operand of type 'const double' (or there is

no acceptable conversion)

Error executing cl.exe.

complex0.obj - 2 error(s), 0 warning(s)

IDE: VC++ 6.0

Can anybody point out the errors with the ">>" overloading?

The overall code is as follows:

// complex0.h -- definition of class Complex

// used for complex operation

#ifndef COMPLEX0_H_

#define COMPLEX0_H_

#include <iostream>

class Complex

{

private:

double real;

double imaginary;

public:

Complex (); // default constructor

Complex (double r, double i);

~Complex (); // destructor

Complex operator- (const Complex & a) const;

Complex operator- () const;

Complex operator~ () const;

friend std::istream & operator>> (std::istream & in, const Complex &

a);

friend Complex operator+ (const Complex & a, const Complex & b);

friend Complex operator* (const Complex & a, const Complex & b);

friend std:stream & operator<< (std:stream & os, const Complex &

a);

};

#endif

// complex0.cpp -- methods for class Complex

// compiled with complex0.h

#include "complex0.h" // constructors

Complex::Complex ()

{

real = imaginary = 0.0;

}

Complex::Complex (double r, double i)

{

real = r;

imaginary = i;

}

Complex::~Complex () // destructors

{

}

// operators overloading

Complex Complex:perator - (const Complex & a) const // substract

Complex a

{

return Complex (real - a.real, imaginary - a.imaginary);

}

Complex Complex:perator - () const // reverse sign

of Complex

{

return Complex (-real, -imaginary);

}

Complex Complex:perator ~ () const // conjugate

sign of Complex

{

return Complex (real, -imaginary);

}

// friends methods

std::istream & operator>> (std::istream & in, const Complex & a)// input

Complex

{

std::cout << "real: ";

in >> a.real;

std::cout << "imaginary: ";

in >> a.imaginary;

return in;

}

Complex operator+ (const Complex & a, const Complex & b) // plus two

Complex

{

return Complex (a.real + b.real , a.imaginary + b.imaginary);

}

Complex operator* (const Complex & a, const Complex & b) // mutiple

Complex a and b

{

return Complex (a.real * b.real , a.imaginary * b.imaginary);

}

std:stream & operator<< (std:stream & os, const Complex & a) //

display Complex

{

os << "(" << a.real << ", " << a.imaginary << ")";

return os;

}