I read this link in Straustup with the following code:
class X { int a; public: X(int x) { if (0<x && x<=max) a=x; else throw bad_X(x); } X() :X{42} { } X(string s) :X{lexical_cast<int>(s)} { }
My question is about the line:
X() X{42}{}
Are there any differences between parentheses and braces?
If there is no difference, can I use curly braces in other function calls? Or is it just a matter of designer? And finally, why should we have both syntaxes? This is a bit ambiguous.
c ++ constructor c ++ 11 delegation
Govan
source share