Why use the keyword ‘const’ twice in a class member function C++

  accessor, c++, oop

I keep running across function definitions inside classes that look like this:

//Accessor function
const string getName() const {
    return name;
}

My question is: why does the word ‘const’ appear twice. I know the ‘const’ at the end of the definition helps protect the original member information, but what does the first ‘const’ do?

Source: Windows Questions C++

LEAVE A COMMENT