Interview Question 3589

Created by admin on Sat, 17/11/2012 - 13:16
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.
Question: 

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(); }

Language: 
Answer: 
5,5