I just learned about the constructor, and there is a question I am not sure, whether Person(10) is actually Person px(10), and then p2 = px. But the printed result is "paramererized constructor!" and "Destructor!" ", there is no "Copy Constructor!". Is the system automatically optimized or I made a mistake?
class Person {
public:
Person() {
cout << "default constructor!" << endl;
}
Person(int a) {
age = a;
cout << "paramererized constructor!" << endl;
}
Person(const Person& p) {
age = p.age;
cout << "Copy Constructor!" << endl;
}
~Person() {
cout << "Destructor!" << endl;
}
public:
int age;
};
int main()
{
Person p2 = Person(10);
return 0;
}