You can create a second method with different parameters, in this case no one will simulate the default parameter:
string& name() {
return _name;
}
And if you need a const getter, just add it!
const string& name() const {
return _name;
}
The compiler will know which one to call that magic overload.
Foo f;
f.name("Smith");
BOOST_CHECK_EQUAL("Smith", f.name());
const Foo cf;
BOOST_CHECK_EQUAL("", cf.name());
source
share