Constructors as Type 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; }
complex(circuit &c); // a new type of constructor!
complex c1; // initialized to 0
complex c2(4.0); // initialized to 4.0 + 0.0i
complex c3(4.0, 5.0); // initialized to 4.0 + 5.0i
complex c4 = 4.0; // new syntax, but identical to c2
// looks like a type conversion!
circuit x; // recall that the voltage of a circuit is
// represented as a complex number
complex c5 = x; // this is a user-defined type conversion:
// complex::complex(circuit &c) is called
// to “convert” type circuit to type complex
// note, unlike previous example, only public
// data can be used from x