What is the difference between
const string& getName() const {return name;}
and
string& getName() const {
const string& getName() const {return name;}
return const reference means that you will not be able the instance after returning the reference to it.
string& getName() const {return name;}
const method means that this method will not change the state of the object except the mutable member variables. Also this method can be called on an const object for example:
class MyClass(){
public:
void doSomethingElse()const;
void notConstMethod();
};
void doSomething( const MyClass& obj ){
obj.doSomethingElse();
obj.notConstMethod(); //Error
}