TITLE: a case for protected virtual functions (Source: comp.lang.c++.moderated, 12 Oct 2000) KANZE: James Kanze >>>> That's interesting, because in new code, all of my virtual >>>> functions are protected. A virtual function should never be >>>> public, of course. MORENO: Carlos Moreno >>> WHAT?!!! So much for virtual destructors, for instance... KANZE: >> You've hit upon the exception, of course:-). I don't tend to >> think of destructors as functions, but of course, the destructor >> normally will be public, and normally will be virtual. DIMOV: Peter Dimov > Another exception: interfaces. > > class abstract_base > { > public: > virtual void method1() = 0; > }; KANZE: No exception here. In most cases, the interface should be more or less: class Interface { public: void fnc() { assert( anyPreconditions ) ; doFnc() ; assert( anyPostconditions ) ; } protected: virtual void doFnc() = 0 ; } ; At an interface between subsystems, it is also not uncommon to insert logging code in the non-virtual public member. There are exceptions to this, however, as I have posted in response to a posting from Gerhard Menzl. _______________________________________________ cpptips mailing list http://cpptips.hyperformix.com