Help! // Suggesting my const functions

I need a little help wrapping my head around what const does:
What I think it does: Const is needed to lock down the variable contents of a function, so that you can CALL a variable, but not change it within the const’d function? I.e. If it is const’d you can call on pre-defined variables from the class, but not re-define those variables? But this is ONLY true of variables that are defined within the class that the const’d function belongs to (i.e. MEMBER variables)? If I wanted to then I could still define a non-member variable inside the const function?
You must also const it at the declaration and definition level, or else they are not recognised as the same function?

Question/Problem: I can still re-define my variables by re-declaring them in the getter functions even after const’ing. Any thoughts on that? Isn’t that problematic?

Regarding which functions should be made const:
It depends on what we choose to do with the other functions I guess. For them to need to be const, the functions will need to take values from variables in the class which we don’t want to change in FBullCowGame,cpp.

Reset => We DO want to change the current try if we reset. So this should NOT be const.

CheckGuessValidity => We are probably limited by what this function can do if it’s returning a Boolean. We might make reference to the current try as we won’t want to increment the current try if it’s not a valid guess, so it’s a candidate for const. But frankly we might want to separate that out into another function as this only returns a Boolean currently (and we like to make functions as simple as possible), so just based on what I consider the scope of this function is… then I conclude, NO it is not a candidate.

IsGameWon => Based just on the variables we have in the .h file… nah. I can’t see how it would use these if the data type we return is boolean. so NO.

Privacy & Terms