WEB DEVELOPER SITE
PYTHONPHPJAVA
 

C++ Constructors


Class constructors are special member functions of a class. They are executed whenever new objects are created within that class.

object of type myClass, the constructor is automatically called.

A default constructor has no parameters

we should parameters can be added to a constructor.

This makes it possible to assign an initial value to an object when it's created, as shown in the following example:

We defined a constructor, that takes one parameter and assigns it to the name attribute using the setName() method.