Member variable declaration

Why do we have to declarer the variables under the private section in the Header file.
like this:
private :
FString HiddenWord;
int32 Lives;

  1. They are member variables because they are part of the class’ state and will be used across multiple functions.

  2. They are private because no other code outside of the class should have direct access to these variables as they could break the workings of the class.

    “Interfaces should be easily to use correctly and hard to use incorrectly”

    Demonstration of what the access specifiers do: Compiler Explorer

1 Like

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

Privacy & Terms