[Cs3] access modifiers and virtual functions

Mikhail Nesterenko mikhail at cs.kent.edu
Fri Oct 25 09:39:21 EDT 2019


CS3 students,

Regarding the question whether the the overriding function has to have
the same access as the base class function. The answer is: NO. 

That is, the base class virtual function may be private while the
derived class function may be public. In this case, the derived class
will not be able to explicitly invoke the base class virtual function
but the run-time late-binding mechanism will operate correctly.

It takes a bit of time to digest (so take your time). Apparently, it
is a topic of discussion in C++ circles. There is even a debate
whether the virtual functions should be made private or protected.

Here is a link for more info:

   https://stackoverflow.com/questions/2170688/private-virtual-method-in-c


Thanks,
-- 
Mikhail


More information about the cs3 mailing list