Constructor creation | Sololearn: Learn to code for FREE!

0

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

+1

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

+2

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"

0

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.