Why private function?

Apologies if this is covered later, but up till now we’ve been making these things as private variables, then giving these values from various functions - I don’t understand why we’ve suddenly changed to making a private function.

Is it just Ben showing us that it can be done - or is there an actual reason why we’re being different?

Cheers in advance

It’s all part of this encapsulation business. It’s just helper function for other functions in the class. Other objects needn’t care about the implementation details; just what it wants to use.

“Make interfaces easy to use correctly and hard to use incorrectly”

Thanks for the answer, I was kinda there, I just don’t get the difference between that and, say, IsGameWon.

Sorry if I’m being obtuse :frowning:

Because main.cpp is the one responsible for the game loop and thus needs to know the state of the game

:facepalm: Right!

Thanks so much for your help :slight_smile:

I don’t understand why anything is private, really. I write allot of python where everything is public – I’ve been tempted to do the same here.

“We’re all consenting adults.” -Guido on encapsulation

This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.

Privacy & Terms