Any function without an assignment is a candidate for const

So both the getters require const.
An interesting thought here is that any function without an assignment could be a candidate for the const.
i.e. any function that doesn’t assign a new value to an object (variables, strings, etc) I think is a valid candidate for const.
But what if one of these functions calls another function that has an assignment statement? Logically I think this ‘should’ break the const property, but I’m not sure. Might just go test this…

2 Likes

So it turns out if a member function is declared as const then it can only call other functions also declared as const. Not sure if they have to be members of the same class, might test this later once we get more classes going.

Yup. This makes sense. So the functions PrintIntro() and WantToPlayAgain() could potentially be const right?

to make a fun const, function should be a member of class, whereas printintro() is not member of class hence it can’t be made const

I think azzzman was suggesting these functions become part of our class; and be made constant.

I personally see it as anything that would need to change in the game (Such as “Get_Current_Try”) Should not be made into a const. As a const (from my understanding at this point) - say with 'Get_Current_Try - value would not be able to change once assigned as const.

Obviously; we would want it to change with each try.

Just my thought… but I’ll continue the lessons from here and find out.

Privacy & Terms