in C Plus Plus by

Delegating Constructors

1 Answer

0 votes
by

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

class M //C++11 delegating constructors

{

int x, y;

char *p;

public:

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.

...