0
Constructor creation
I don't understand, a constructor is called when you create an object or when you declare one?
3 Answers
+ 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.