1

What means '&' before getter?

const std::string &getName() const {
        return Name;
}

getter was generated by CLion ide

  • 5
    It means it returns a reference. – Jerry Coffin May 24 '15 at 23:56
  • 3
    possible duplicate of [Implications of using an ampersand before a function name in C++?](http://stackoverflow.com/questions/8610350/implications-of-using-an-ampersand-before-a-function-name-in-c) – AliciaBytes May 25 '15 at 00:00

1 Answers1

4

It's part of the return value's data type.

Rearranging whitespace,

const std::string&
getName()
const
{...}

This is a function named getName which takes no parameters, doesn't modify object members, and which returns a value of type const std::string&. This data type can be read as "reference to a const string".

Ryan Bemrose
  • 9,018
  • 1
  • 41
  • 54