Constructor delegation lets one constructor of a class call another constructor of the same class from its member initialiser list. It was added in C++11 and exists to put shared initialisation logic in a single place instead of repeating it in every overload. It is also known as constructor chaining in other languages.
The syntax is a constructor whose initialiser list contains only a call to another constructor of the same class: Widget() : Widget(0, 0) {}. This article explains the rules, the order of execution, a realistic example, and the pitfalls such as circular delegation and exceptions.
A delegating constructor names the target constructor in its initialiser list, using the class name.
The target constructor runs to completion first, then the body of the delegating constructor runs. Once the target has finished, the object counts as fully constructed.
A() delegates to A(int) and A(int) delegates back to A(), the program is invalid (compilers are not required to diagnose it, so avoid it).Centralising checks in the target constructor means every overload gets them.
Both short forms funnel into the three-argument constructor, so the validation exists once.
Delegation is not always the best tool. Compare the options.
| Technique | Best for | Limitation |
|---|---|---|
| Default arguments | Trailing parameters with fixed defaults | Defaults are baked in at the call site, one constructor only |
| Default member initialisers | Members with a constant default value | Cannot validate or compute from arguments |
| Delegating constructors | Different parameter lists sharing setup logic | Delegation must be the only initialiser |
Private init() function | Pre-C++11 code | Members are default-constructed first, then assigned |
A common modern combination is default member initialisers for the simple cases and one target constructor for anything that needs logic.
An object is considered constructed as soon as any one constructor finishes. With delegation, that means once the target constructor completes, a destructor will run for the object even if the delegating constructor's body then throws.
If you call Probe p; inside a try block, the output is target done followed by destructor runs. Keep that in mind when the delegating constructor does extra work after the target: it must leave nothing half-built that the destructor cannot handle.
Constructor delegation reuses constructors inside one class. A separate C++11 feature, inheriting constructors, reuses a base class's constructors in a derived class with a using-declaration.
Use delegation when the constructors belong to one class and inheriting constructors when the derived class adds no new data that needs initialisation.
No. If the initialiser list contains a delegation, it can contain nothing else. Put the member initialisation in the target constructor.
It adds one extra constructor call, which compilers usually inline. The cost is generally negligible.
C++11. All current compilers support it in every language mode from C++11 upward.
No. A base constructor call is part of the normal initialiser list, while delegation calls another constructor of the same class and replaces the whole list.
Constructor delegation, available since C++11, lets one constructor forward to another constructor of the same class so initialisation logic lives in one target constructor. The delegating constructor can have only that call in its initialiser list, cycles are not allowed, and the target completes before the delegating body runs. Combine it with default member initialisers for concise, maintainable classes.