More User-Defined Conversions
float p_real, p_imaginary;
complex() { p_real = 0.0; p_imaginary = 0.0; }
complex(float r) { p_real = r; p_imaginary = 0.0; }
complex(float r, float i) { p_real = r, p_imaginary = i; }
// we can overload the int() typecasting operator! cool!
operator int() { return round(p_real); };
circuit cir; // recall that the voltage of a circuit is
// represented as a complex number
complex c5 = cir; // this is a user-defined type conversion:
// using complex::complex(circuit &c);
int i = c5; // now cal complex::operator int() to convert
int j = cir; // doesn’t work, the compiler won’t automatically
// find a series of conversions for you
int k = complex(cir); // this works, circuit->complex->int