PRODUCT : Borland C++ NUMBER : 1334 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 1/2 TITLE : What is 'Virtual Function Hiding' ? This document explains the meaning and reasons for the Compiler warning message: "Derived::X(int) hides virtual function Base::X()" First, let us look at a simple code fragment that generates the warning mentioned above: class Base { public: virtual void f() {} }; class Derived_1 : public Base { public: virtual void f( int ) {} }; class Derived_2 : public Derived_1 { public: virtual void f() {} }; int main( void ) { Derived_1 d1; Derived_2 d2; d1.f(1); d2.f(); return 0; }; The example code given above will generate the following messages when submitted to the compiler: Warning 'Derived_1::f(int)' hides virtual function 'Base::f()' PRODUCT : Borland C++ NUMBER : 1334 VERSION : 3.x OS : ALL DATE : October 26, 1993 PAGE : 2/2 TITLE : What is 'Virtual Function Hiding' ? Warning 'Derived_2::f() ' hides virtual function 'Derived_1::f(int)' Basically, if the same virtual function(s) defined in a base class and a derived types are different [disparate parameters] the virtual mechanism is no longer invoked; Hence the compiler's warning about the new function 'Hiding' the base function. Calls to virtual functions are performed indirectly through the vtble (pronounced vee-table). Each C++ object with virtual functions contains a pointer to the vtble for that object class. For example let's assume a base class containing two virtual functions, vf1() and vf2(). Then let's have another class derive from the base class and overriding ( ie. redefining ) only one of the virtual functions, vf2(). The vtble for the derived class would contain a pointer to the base class' vf1() and pointer to its own version of vf2(). However, if the derive class contains a function of similar name to one of the virtual functions in the base but with different paramanters, the derive class no longer 'sees' the base class version of that function: ie. The new function hides the base class version. So when Dervied_1 in our example added f(int) the virtual mechanism was disabled, and the new version of function 'f( int )' is treated as a totally new function. NOTE: Though not illustrated in our example, it is an error for a derived class' virtual function to differ from the base class' virtual function only in return type. Virtual function hiding is usually regarding as bad practice by the C++ community. If you would like further details on this topic consult Sections 10.2 and 13.1 of the Annotated C++ Reference Manual ( ARM ). DISCLAIMER: You have the right to use this technical information subject to the terms of the No-Nonsense License Statement that you received with the Borland product to which this information pertains.