constructor calling another constructor c++ code example

Example 1: call constructor from another c++

//You can use delegating constructor (since C++11) like this:
Foo(int iX)  {
    // ...
}; 

Foo() : Foo(10) {
  
}

Example 2: how to call one constructor from the other constructor

With in the same class if we want to call one constructor 
from other we use this() method. Based on the
number of parameters we pass appropriate this() method is called.
Restrictions for using this method :
1) this must be the first statement in the constructor
2)we cannot use two this() methods in the constructor

From base class: by using super() keyword to call constructor 
from the base class

Tags:

Cpp Example