TITLE: Use virtual keyword explicitly in derived classes RESPONSE: jamshid (Jamshid Afshar), 2 Jun 94 It's a good idea to keep the keyword "virtual" on member functions of a derived class. Although the compiler doesn't need to be told that a member function defined in a derived class is virtual, humans often do: // in design/tedgepath.h class TEdgePath { //... public: virtual TString buildPathName( boolean useNickNames = TRUE ); }; // in obDesign/tobpath.h class TOBPath : public TEdgePath { //... public: TString buildPathName( boolean useNickNames = TRUE ); // okay: compiler knows that this is a virtual function, but // programmer might not }; Someone editing tobpath.h might want to add another parameter to TOBPath::buildPathName(). Unless they've been looking in tedgepath.h, they wouldn't realize that by adding the parameter they are no longer overriding the base class's member function: // in obDesign/tobpath.h class TOBPath : public TEdgePath { //... public: TString buildPathName( boolean useNickNames = TRUE, boolean listPageKind = FALSE ); // woops: now TOBPath::buildPathName() hides, not overrides, // TEdgePath::buildPathName() }; By always using the virtual keyword when overriding a member function in a derived class, you remind future programmer that they shouldn't mess with the parameters: // in obDesign/tobpath.h class TOBPath : public TEdgePath { //... public: // overrides base function; calls buildPathName(TRUE,FALSE) virtual TString buildPathName( boolean useNickNames = TRUE ); // new function with extra option virtual TString buildPathName( boolean useNickNames, boolean listPageKind ); }; Fortunately, most compilers now warn whenever you define a function in a derived class that has the same name as a base virtual function but different parameters: "warning: TOBPath::buildPathName() hides virtual TEdgePath::buildPathName()".