Sololearn: Learn to Code
New course! Every coder should learn Generative AI!
Try a free lesson
+ 3
There are 3 objects here, that is why. 0) The object mybd in main. 1) The object bd of class Human. 2) The object b which is a formal parameter to Human's constructor. First mybd is initialized, which is passed by value to Human's constructor for Daniel. Then a copy of the object is made and stored in b, which is passed to bd for data. Finally, b gets destroyed, followed by Daniel's bd and the object mybd. Thus 3 destructor calls take place. Accepting the Birthday object by reference (normal, const or rvalue) in the constructor reduces the number of objects created.
2nd Mar 2019, 10:30 AM
Kinshuk Vasisht
Kinshuk Vasisht - avatar