Delegating constructors

A constructor may call another constructor using the same member list syntax:

    class car     {         // data members     public:         car(double front, double back, double s = 25.0)             : tire_pressures{front, front, back, back}, spare{s} {}         car(double all) : car(all, all) {}     };

Here, the constructor that takes one value delegates to the constructor that takes three parameters (in this case using the default value for the spare).

Get Beginning C++ Programming now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.