Constructor Overloading C++, Sum of n number of odd natural numbers

Let’s see the C++ program to show the Sum of n number of odd natural numbers by using the Constructor Overloading.

We are using more than one constructor of the class T4Tutorials_Sum_Constructor_Overloading with the same name, and it is called constructor overloading.

In this program, the constructor must obey one or both of the following rules.

  1. All constructors with the same name and having a different number of parameters.
    • T4Tutorials_Sum_Constructor_Overloading (int a) and another constructor as T4Tutorials_Sum_Constructor_Overloading(int two, int three).
  2. All constructors with the same name and have the same number of parameters but of different data types.
    • T4Tutorials_Sum_Constructor_Overloading (int a) and another constructor as T4Tutorials_Sum_Constructor_Overloading (double a).

Note: In this example, we are overloading the constructor with the following rule;

T4Tutorials_Sum_Constructor_Overloading(int a) and another constructor as T4Tutorials_Sum_Constructor_Overloading(int two,int three).

 

Output

Constructor Overloading C++, Sum of n number of odd natural number