As stated in the booking I'm reading:
"In order to be able to invoke get()
also, if we only have a pointer or reference to a const TextureHolder
at hand, we need to provide a const-qualified overload. This new member function returns a reference to a const sf::Texture
, therefore the caller cannot change the texture. ... "
And then the author goes onto provide this example of the overloaded function definition:
const sf::Texture& TextureHolder::get(...) const;
I understand that if you have a reference or pointer to a const TextureHolder
, you cannot modify it. Thus the return type of const sf::Texture&
.
But why the appended const
at the end of the function definition? Isn't that to only have a pointer to a constant this
, so you cannot modify class member variables? So what purpose does that serve if our function isn't trying to modify any member/object variables?
For the curious, here is the full function:
sf::Texture& TextureHolder::get(Textures::ID id){
auto found = mTextureMap.find(id);
return *found->second;
}
~~~~~~~~~~
Being new to the language, I'm still getting over the million (I know, exaggerating a bit there) different uses of const
in the C++ language.