Class X{X(){}X(X &obj){} // supose '=' operator is also overloaded for this class. I am not writing code for that }main(){X a;X b = a;X c(&a);X d;d = a;}What is the difference between a, b, c, d objects ?

Questions by smart_coder   answers by smart_coder

Showing Answers 1 - 3 of 3 Answers

Rajesh

  • Feb 6th, 2007
 

X b = a; --calls copy constructor as here new object will be created.X c(a); copy constructord = a; normal assignment so = operator comes into picture.

  Was this answer useful?  Yes

swetha

  • Feb 20th, 2007
 

x a;  -  calls default constructor

X b = a;  - calls copy constructor
X c(a);    - calls copy constructor
X d;       - calls default constructor
d = a;    -   calls overloaded = operator.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.