Search code examples
c++oopclass-designprivate-methods

When/why to make function private in class?


When should i make a function private and why is it good idea?


Solution

  • You should make a function private when you don't need other objects or classes to access the function, when you'll be invoking it from within the class.

    Stick to the principle of least privilege, only allow access to variables/functions that are absolutely necessary. Anything that doesn't fit this criteria should be private.