Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Foo
- {
- public:
- std::string& Name()
- {
- m_maybe_modified = true;
- return m_name;
- }
- const std::string& Name() const
- {
- return m_name;
- }
- protected:
- std::string m_name;
- bool m_maybe_modified;
- };
- Foo *a;
- // Do stuff...
- std::string name = a->Name(); // <-- chooses the non-const version
- const Foo* b = a;
- std::string name = b->Name();
- std::string name = b->Name();
- b->Name() = "me";
Add Comment
Please, Sign In to add comment