How Many Types of Constructor are Available in C++? Explain them - CodeTextPro | Free Web Tutorial

Codetextpro Provides free Web tutorial, HTML, CSS, C, C++, Java, JavaScript, PHP, MySql, Python, Program, Programming Notes, Programming Questions and more.

Saturday, August 10, 2019

How Many Types of Constructor are Available in C++? Explain them

There are mainly three types of constructor available in C++ are the following:

1. Default Constructor - A constructor that accepts no parameter is known as default constructor. If no constructor is defined then the compiler supplies a default constructor. It means that C++ compiler has an implicit constructor which create an object even though it was not defined in the same class.

student :: student(){}
student :: student()

2. Parameterized Constructor - A constructor that receives one or more than arguments/parameter, is called a parameterized constructor.

student :: student(int r, float m)

3. Copy Constructor - A constructor that initializes an object using values of another object passed to it as parameter, is called copy constructor. It creates an alias of the passed object or reference to the passed object.

student :: student(student &t)

1 comment:

  1. What about the move constructor? Unlike the copy constructor which copies the member variables, the move constructor moves them completely to a new variable