#include <iostream> using namespace std; class Complex{ public: Complex(); Complex(int,int); Complex(int); Complex(const Complex & c); Complex & operator=(const Complex & r); void getValue(); private: int m_value; int m_real; }; Complex::Complex() { m_value = 2; m_real = 3; } Complex::Complex(int value,int real) { m_value = value; m_real = real; } Complex::Complex(int r) { m_value = r; m_real = -1; } Complex::Complex(const Complex & c) { m_value = c.m_value; m_real = c.m_real; } Complex & Complex::operator=(const Complex & r) { m_value = r.m_value + 1; m_real = r.m_real + 1; } void Complex::getValue() { cout<<"my value is "<<m_value<<endl; cout<<"my real is "<<m_real<<endl; } int main() { Complex c1,c2; //对应于 Complex(); c1.getValue(); c2.getValue(); Complex c3(5,6);//对应于Complex(int,int); c3.getValue(); Complex c4=c3;//对应于 Complex(const Complex & c); c4.getValue(); c1 = c4;//对应于Complex & operator=(const Complex & r); cout<<"focus"<<endl; c1.getValue(); Complex c5 = 90;//对应于Complex(int); c5.getValue(); return 0; }