Transport(string str1, string str2) //Constructor2 Transport bike(2) // Calling the parameterized constructor for the 2nd object Transport car(4) // Calling the parameterized constructor for the 1st object Transport(int n) // parameterized constructor Let us see how a constructor is automatically executed at the time of object creation.Įxample(int x) // parameterized constructorĮxample e1(36) // Calling the parameterized constructorĮxample e2(e1) // Calling the copy constructor ConstructorĪ constructor is a special member function used to initialize objects of its class. It will be called automatically when the object is created. Let us begin by first understanding what a constructor is before we dive in what copy constructor in C++ is. In other words, it creates a copy of an existing object of the class.
0 Comments
Leave a Reply. |