Oops! It appears that you have disabled your Javascript. In order for you to see this page as it is meant to appear, we ask that you please re-enable your Javascript!

Constructor of a class, Purpose of Constructor in C++ OOP

Last modified on January 3rd, 2019 at 3:04 pm

Constructor of a class, Purpose of Constructor in C++ OOP

Today, in this fresh and new article, we will cover the following topics;

  1. What is the constructor of a class?
  2. What is the purpose of a class?
  3. Program of the constructor of a class

What is a constructor in C++ OOP?

The constructor is a member function of the class. The constructor has the same name as the name of its class.

  1. When a new object of the class is executed, constructor also executed automatically.
  2. The constructor has no data type. Even we can’t use void also.
  3. The constructor can have arguments.

What is the purpose of the constructor of a class?

The main purpose of the constructor is to assign initial values to the elements of the class.

Program of constructor of a class

2 using namespace std;
3 class t4tutorials
4 {
5 public:
6 t4tutorials() {
7 cout<<“welcome to T4Tutorials.com”<<endl;
8 }
9 };
10int main(){
11t4tutorials x;

Constructor is declared in line 3 with the same name as class name “t4tutorials”. When object in line 11 is created then constructor in line 3 is automatically executed.

Test Your Understandings

1.Multiple constructor for a class are possible? YES / NO

Answer - Click Here:

2. Contructor for a class is represented with tild sign ∼?

Answer - Click Here:

3. Constructor overloading is  very helpful to free the computer memory?

Answer - Click Here:

Topic Covered

Constructor of a class, Purpose of Constructor in C++ OOP.

Prof. Fazal Rehman Shamil
Researcher, Publisher of International Journal Of Software Technology & Science ISSN: 2616-5325
Instructor, SEO Expert, Web Programmer and poet.
Feel free to contact.