in C Plus Plus by
Q:

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.

Related questions

+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
+1 vote
asked Jan 2, 2020 in C Plus Plus by GeorgeBell
  • c
0 votes
asked Jan 2, 2020 by GeorgeBell
+1 vote
asked Mar 17, 2020 in C Plus Plus by SakshiSharma
...