Can a primitive-type data member of a derived class be used as a parameter to its base constructor?
14
2
Inspired by my (currently deleted) answer to this question (but there's a summary in my comment thereto), I was wondering whether the constructor for the Derived class in the code below exhibits undefined behaviour. #include <iostream> class Base { public: Base(int test) { std::cout << "Base constructor, test: " << test << std::endl; } }; class Derived : public Base { private: int variable; public: Derived() : Base(variable = 50) { // Is this undefined behaviour? } }; int main() { Derived derived; return 0; } I know that, when the base c'tor is called, the derived object has not yet (formally) been constructed, so the lifetime of the variable member has not yet started. However, this e...