According to the C ++ standard (8.3.6 default arguments):
9 The default arguments are evaluated each time the function is called. The evaluation order of the function arguments is not specified. Therefore, function parameters should not be used in the default argument , even if they are not evaluated. Parameters A function declared before the default argument is in scope and can hide namespace and class member names.
In any C ++ (not just C ++ 2014) you can overload the constructor. for instance
struct Foo { Foo(int val ) { Foo2 f(val); } Foo(int val, Foo2 f ) {} };
Or you can use the delegation constructor (if your compiler supports the new standard)
struct Foo { Foo(int val ) : Foo( val, Foo2( val ) ) {} Foo(int val, Foo2 f ) {} };
source share