Код: Выделить всё
class Foo {
std::string m_val;
public:
void set(const std::string v) {
m_val = v;
}
const std::string get() const {
return m_val;
}
};
int main() {
Foo f;
f.set("Hello world!");
/* (1) Wrong
f.get() = "Thanks";
*/
/* (2) You can change the "retVal" value except if you used const with "retVal".
std::string retVal = f.get();
retVal = "Thank you";
*/
return 0;
}
Подробнее здесь: https://stackoverflow.com/questions/797 ... tion-metho