I found this construct some time ago. It took some reading to understand why it worked. I’m still not sure if it is actually legal, or just works only because m_derivedData is not accessed in Base::Base.
1 2 3 4 5 6 7 8 9 10 11 |
struct Base { std::string& m_derivedData; Base(std::string& data) : m_derivedData(data) { } }; struct Derived : public Base { std::string m_data; struct Derived() : Base(m_data), m_data("foo") { } }; |
Recent Comments