- #include <iostream> 
-   
- // Version 1: (return type fixed) 
-   
- class Complex1 { 
-   friend std::ostream& operator << (std::ostream &out, const Complex1 &c); 
-   private: 
-     int a; 
-   public: 
-     explicit Complex1(int a): a(a) { } 
-     // operator + as member 
-     Complex1 operator + (const Complex1 &c) const 
-     { 
-       return Complex1(a + c.a); 
-     } 
- }; 
-   
- std::ostream& operator << (std::ostream &out, const Complex1 &c) 
- { 
-   return out << c.a; 
- } 
-   
- // Version 2: (two overloaded operators) 
-   
- class Complex2 { 
-   friend std::ostream& operator << (std::ostream &out, const Complex2 &c); 
-   friend int operator+(const Complex2 &c, const Complex2 &d); 
-   friend int operator+(int c, const Complex2 &d); 
-   private: 
-     int a; 
-   public: 
-     explicit Complex2(int a): a(a) { } 
-   
- }; 
-   
- std::ostream& operator << (std::ostream &out, const Complex2 &c) 
- { 
-   return out << c.a; 
- } 
-   
- int operator+(const Complex2 &c, const Complex2 &d) 
- { 
-   return c.a + d.a; 
- } 
-   
- int operator+(int c, const Complex2 &d) 
- { 
-   return c + d.a; 
- } 
-   
- // Version 3: (implicit conversion with constructor) 
-   
- class Complex3 { 
-   friend std::ostream& operator << (std::ostream &out, const Complex3 &c); 
-   private: 
-     int a; 
-   public: 
-     Complex3(int a): a(a) { } 
-     // operator + as member 
-     int operator+(const Complex3 &c) const 
-     { 
-       return a + c.a; 
-     } 
- }; 
-   
- std::ostream& operator << (std::ostream &out, const Complex3 &c) 
- { 
-   return out << c.a; 
- } 
-   
- // Check everything out: 
-   
- using namespace std; 
-   
- int main() 
- { 
-   cout << "Version 1:" << endl; 
-   { Complex1 c1(3), c2(5), c3(2); 
-     Complex1 c4 = c1 + c2 + c3; 
-     cout << "c4: " << c4 << endl; 
-   } 
-   cout << "Version 2:" << endl; 
-   { Complex2 c1(3), c2(5), c3(2); 
-     Complex2 c4 = Complex2(c1 + c2 + c3); 
-     cout << "c4: " << c4 << endl; 
-   } 
-   cout << "Version 3:" << endl; 
-   { Complex1 c1(3), c2(5), c3(2); 
-     Complex1 c4 = c1 + c2 + c3; 
-     cout << "c4: " << c4 << endl; 
-   } 
-   cout << "done." << endl; 
-   return 0; 
- } 
-