Chapter 13: Problem 9
Under what circumstances should a member function be private?
Short Answer
Expert verified
Answer: A member function should be declared as private in three main circumstances:
1. When it acts as a helper function, performing specific tasks needed by one or more public member functions but not intended for direct external usage.
2. When it enforces a class invariant, maintaining conditions that must always hold true for an object of the class during its lifetime.
3. When it's necessary to control or restrict its usage, ensuring that the function's usage follows specific rules or guidelines and making it easier to reason about the class's behavior.