Why constructor is called twice?

This is because when you do the following: obj2 = 100 ; this one will first call abc(int x) to generate an object of the class, then call the default copy assignment operator (since no user-defined is provided) to assign the value 100 to existing obj2 . After the assignment, the temporary object is destructed.

Sizin İçin Seçtik  What are types of constructor in C++?

Leave a Reply

Your email address will not be published. Required fields are marked *