
上QQ阅读APP看书,第一时间看更新
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).