Instead of indicating a pointer to an object, the "&" indicates a reference (In your case a constant reference).
The benefit of including a feature like
foo(string const& myname)
over
foo(string const* myname)
is that because C++ does not permit NULL references, you are assured that myname is not null in the first scenario.
The object is not cloned because you are passing by reference, exactly like if you were passing a pointer.
Your second illustration
const string &GetMethodName() { ... }
would enable you to return a reference to a member variable, for instance, that is constant.
This is helpful if you want to ensure that the value returned is non-null but do not want a copy to be returned.
For illustration, you have immediate, read-only access to the following:
class A
{
public:
int bar() const {return someValue;}
//Big, expensive to copy class
}
class B
{
public:
A const& getA() { return mA;}
private:
A mA;
}
void someFunction()
{
B b = B();
//Access A, ability to call const functions on A
//No need to check for null, since reference is guaranteed to be valid.
int value = b.getA().bar();
}
Naturally, you must use caution to avoid returning faulty references.
The following will be gladly compiled by compilers (depending on your warning level and how you treat warnings)
int const& foo()
{
int a;
//This is very bad, returning reference to something on the stack. This will
//crash at runtime.
return a;
}
In essence, it is your duty to confirm that the object you are returning a reference to is legitimate.