20.09.2013 23:09, Jonathan M Davis пишет:
You can use NVI with classes just fine just so long as you use protected rather
than private, but making it private there won't work either, because private
is never virtual (and it wouldn't really help you any if it were, because
while the base class private function might not be callable, the derived class
one would still be callable by the derived class, so trying to prevent the
virtual function in NVI from ever being called outside of the base class is
broken in the first place - including in C++ where it was originally devised).
What NVI helps with is making it so that the public function being called as
part of the API is non-virtual, allowing you to do stuff before and after the
hidden virtual function being called, but the derived classes can still call
their implementation of the hidden, virtual function.
- Jonathan M Davis
I see. Thanks for clarifying.