Constructor creation | Sololearn: Learn to code for FREE!


Constructor creation

I don't understand, a constructor is called when you create an object or when you declare one?

1/14/2019 6:15:50 PM

Celumusa Duma

3 Answers

New Answer


The constructor is the part of the object in which the initial data of this object is declared when it is created.


The constructor is called when you create an Object of that class..All its operations are executed right away.. Eg... class sample{ sample(){ cout<<"Hello World"; } } //create object sample object; //outputs "hello world"


If you declare (write) a (non-static) class, nothing is called there. This is a passive definition archived for future use. If you create an object using a class as a rule, by assigning it to the variable, the new object will be initialized with the constructor if the class has it.