I would like to know where I can find some documentation about the following behavior:
class Foo {
public:
Foo(int argX) : Foo(argX, defaultYValue) {}
Foo(int argX, int argY) : x(argX), y(argY) {};
private:
const int x;
const int y;
const int defaultYValue = -1;
}
Might it be possible that y value is undefined ? Or is there some documentation in the standard that tells that it works (I did noticed that the default member initialization is discarded if it is otherwise overridden inside the constructor)
PS: this was discovered while forgetting the static for defaultYValue.
x
not be initialized? Did you perhaps means to ask abouty
whose value depends ondefaultYValue
in the first constructor?: Foo(argX, defaultYValue)
? This works fine, it is called a delegating constructor, doc: en.cppreference.com/w/cpp/language/constructor