merci bien pour toutes ces reponses
Code :
- #include <iostream.h>
- class Complex{
- double real;
- double imaginary;
- public:
- Complex();
- Complex(double,double);
- friend ostream& operator << (ostream&,const Complex& );
- void operator +=(const Complex& );
- friend Complex operator +(const Complex&,const Complex& );
- };
- void Complex::operator +=(const Complex& c){
- this->real+=+c.real;
- this->imaginary+=c.imaginary;
- }
- Complex operator+(const Complex &a, const Complex &b){
- Complex tmp(a);
- tmp+=b;
- return tmp;
- }
- ostream& operator << (ostream& out,const Complex& c){
- out << c.real << " " << c.imaginary;
- return out;
- }
- Complex::Complex(){
- real=0.0;
- imaginary=0.0;
- }
- Complex::Complex(double r=0.0,double i=0.0){
- real=r;
- imaginary=i;
- }
- void main(){
- Complex c1(5,4);
- Complex c2(7,9);
- Complex c3;
- c3=c1+c2+c2;
- c3=c3+5;
- c3=5+c3;
- cout << c3;
- }
|
jarrive pas a virer le Complex::Complex sinon il bloque sur la construction de c3 -> Complex c3;
et si je le laisse comme ca il me fait 'Complex::Complex' : ambiguous call to overloaded function
sinon c mieux de surdef += meme si on lutilise pas , c un principe c ca ???
Message édité par red faction le 09-07-2003 à 18:54:34