l*****d 发帖数: 359 | 1 for example, define a class of complex numbers (use int for simplicity).
class complex_int{
public:
complex_int(int); // constructor 1
complex_int(int, int); // constructor 2
friend complex_int operator+(complex_int&,complex_int&); // friend operator+
operator int(){return real;} // ****conversion to int*****
void print_out(){cout << real << '+' << imag << "i\n";} // display the
complex number
private:
int real;
int imag;
};
if I define two complex_int a and b,
and do "b=a+2".
This is an ambiguo |
|