Posted on 2012.Apr.06, 11:46 pm By Jason
I know people bag on c++ (for many valid reasons) but it still amazes me to learn something new: read only members using const references. It’s even better when a c++ non-fan teaches you about it. Thanks Nico!
class Test { public: Test() : readOnlyVersion(m_writableVersion) {} const SomeType & readOnlyVersion; private: SomeType m_writableVersion; };
Never having a need, I had always filtered out reference data members – I just categorized them with static members and their special initialization. Now that I see a use case, I’m basking in the “Ah that makes total sense” moment.
Categories: C++, Code Tags: c++, code