Given the example:
inline string &GetLabel( ) {
return m_Label;
};
Where m_Label is a private class member variable.
The ampersand isn't before the function name so much as it's after the return type. it returns a reference to a string
.
The implication of this is that a caller of this function could modify the value of m_label
through the reference. On the other hand, it avoids copying the string. You might want the reference and the function to be const
, like so:
inline const string& GetLabel() const
{
return m_Label;
}
Best of both worlds. You avoid the copy, but callers can't change your object.