In the following code the constructor is called only once (i.e.) when Car() executes. Why is it not called the second time on the statement Car o1(Car())?
#include <stdio.h>
#include <iostream>
class Car
{
public :
Car()
{
std::cout << "Constructor" << '
';
}
Car(Car &obj)
{
std::cout << "Copy constructor" << '
';
}
};
int main()
{
Car();
Car o1(Car()); // not calling any constructor
return 0;
}
See Question&Answers more detail:os