By returning an object reference, the const specifier will not allow the object to be modified:
const int& foo() { ... } int main () { foo=5; //error: assignment of read-only location 'f()' return 0; } But how will const int foo () differ from int foo ()? We are talking about functions NOT class members.
And do I understand correctly that the function that returns the link can be used as an lvalue ?:
int& foo() { ... } int bar() { ... } int main () { foo=5; //OK bar=5; //error return 0; }
Но чем будет отличаться const int foo()? Did you meanconst int & foo()? - Cerbo