I am using wxWidgets where, if you have ever used it, you will know that there are a lot of public functions in the base class. I recently ran into a situation where I would not want a method SetText()
be called directly from the derived class. That is, the derived class inherited the SetText()
function but I do not want this function to be available to clients. Instead, I am providing two new functions which call SetText()
but not before some extra operations are performed.
Currently, the client (me!) can forget to call the special functions and simply call SetText()
. Consequently, some extra operations will not be performed. These operations are subtle enough that it may be overlooked easily.
So, can I mark individual functions as private so that the client cannot possibly call them OR simply make it impossible for clients to call it directly (they will have to use my functions to call it indirectly)?
Note that SetText()
is not virtual.
EDIT: To future programmers who stumble on this question, check both the marked answer and Doug T.'s answer.