Are there other methods that you could use const

I would argue no. While CheckGuessValidity() and IsGameWon() are merely checking something, they are still setting a result to either true or false instead of merely grabbing an already set value. Const I would think would be counterproductive in those cases.

Sorry mate but you’re wrong.

Think of const method as a method which does not modify the object’s state. It can do anything it wants with its current scope (method’s braces), but the added const is a promise that it won’t change any of the object’s (i.e. class instance) variables.

Try it yourself! Add a const (both in .h and .cpp) to IsGameWon function. The compiler should be perfectly happy about that change*! :slight_smile:

*unless you assigned to any instance variable obviously, as I don’t see your code to make sure about that.

Privacy & Terms