Candidates for Const

Hi,

Have been working on understanding this. The key point that I was tripped up on was Const stops a member function from changing any class data.

The confusion came from the naming of public and private areas within the class. Just because GetCurrentTry() has become GetCurrentTry() const, does not mean we cannot change int MyCurrentTry. CheckGuessValidity will change MyCurrentTry(as Ben mentioned); a member function which is not const.

To summarise, getters should be const, and it seems like logic can be dealt with in other ways (like the upcoming constructor?).

2 Likes

Hello,

I am thinking, and without having proceeded further in the lesson yet, that you are correct? Though I wonder if that means ALL Getters will be const or it depends on what the class is doing?

Gah so many definitions and words to use all at once. This is going to take some time to absorb x)

1 Like

Privacy & Terms