Ex 1: Find the output of the following program
class complex{
double re;
double im;
public:
complex() : re(0),im(0) {}
complex(double n) { re=n,im=n;};
complex(int m,int n) { re=m,im=n;}
void print() { cout<
};
void main(){
complex c3;
double i=5;
c3 = i;
c3.print();
}
Ans:
5,5
Explanation:
Though no operator= function taking complex, double is defined, the double on the rhs is converted into a temporary object using the single argument constructor taking double and assigned to the lvalue. |