Re[2]: Перегрузка <<
От: O-Sam Россия  
Дата: 26.07.04 12:04
Оценка:
GIV>
GIV> ostream& operator<< (ostream& s, const Complex& z)
GIV>


Однако, странности:

Z:\Heap\Coding\Cpp\iotest\main.cpp(30) : error C2593: 'operator <<' is ambiguous
Error executing cl.exe.



#include <iostream>
using namespace std;

class Complex
{
    double re;
    double im;
public:
    Complex (double re, double im);
    double real() const {return re;}
    double imag() const {return im;}
    friend ostream& operator<< (ostream& s, const Complex& z);
};

Complex::Complex (double re, double im)
{
    this->re = re;
    this->im = im;
}

ostream& operator<< (ostream& s, const Complex& z)
{
    return s << '(' << z.real() << ',' << z.imag() << ')';
}


void main(void)
{
    Complex a(1.2,0.2);
    cout << "a=" << a;
}
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.