Copy Constructor Quiz-Asked in Interviews.
When is a Copy constructor is invoked?
A) Instance of a class is Created
B) Argument is passed by reference
C) Argument is passed by reference
D) Function returns by value
Solution: D is correct
In C++, a Copy Constructor may be called for the following cases:1) When an object of the class is returned by value.
2) When an object of the class is passed (to a function) by value as an argument.
3) When an object is constructed based on another object of the same class.
4) When the compiler generates a temporary object.