Why MyHiddenWord.length()?

So I used GetHiddenWordLength() instead of MyHiddenWord.length()

I’ve tried it both ways and works in either case, but is there a reason for not going through the getter on this one?

Thanks for any enlightenment
Sid

You have getter functions in place to access private variables from OUTSIDE your class while preventing them to be modified from the outside, basically if you needed to check that variable from main.cpp but not want to accidentally change it. Conversely, inside the class you can access it both ways, and in the case you choose to use GetHiddenWordLength(), those kind of functions usually just internally calls and returns MyHiddenWord.length(), then you’re making 2 functions call, you could instead just call directly MyHiddenWord.length() and have only 1 function call since you are already inside the class.

1 Like

Privacy & Terms