in c++, since does compiler select non-const duty const work also?
for example, suspect i have class:
class foo
{
public:
std::string& name()
{
m_maybe_modified = true;
relapse m_name;
}
const std::string& name() const
{
relapse m_name;
}
protected:
std::string m_name;
bool m_maybe_modified;
};
and somewhere else code, i have something this:
foo *a;
// stuff...
std::string name = a->name(); // <-- chooses non-const version
does anyone know since compiler select non-const chronicle case?
this rather constructed example, nonetheless tangible problem perplexing solve intermittently auto-saving an vigilant changed, pointer contingency non-const since competence altered during point.
Comments
Post a Comment