Jan 2 in C++

Delegating Constructors

1 Answer

Jan 2

In C++11 a constructor may call another constructor of the same class:

class M //C++11 delegating constructors


int x, y;

char *p;


M(int v) : x(v), y(0), p(new char [MAX]) {} //#1 target

M(): M(0) {cout<<"delegating ctor"<<endl;} //#2 delegating


Constructor #2, the delegating constructor, invokes the target constructor #1.

Click here to read more about C++
Click here to read more about Insurance

Related questions

Jan 2 in C++
Mar 17 in C++
Jul 16, 2019 in C++