[GCC-XML] virtual function

Brad King brad.king at kitware.com
Sat Feb 2 09:21:35 EST 2008

Nindi Singh wrote:
> class Base {
>   public:
>     virtual void func()=0;
> };
> class Derived:public Base {
>   public:
>     void func(){}
> };
> I am curious the method 'func' in class Derived is described as virtual. Its not. If I am missing something, then how can I tell whether a function 'may' be overloaded in a derived class or not.

Yes, it is declared virtual.  It does not matter whether the virtual 
keyword is present.  If there is a function with the same signature in 
the parent class that is declared virtual it implicitly makes your 
function virtual.  This is a C++ rule.

If instead you write

class Base {
     virtual void func()=0;
class Derived: public Base {
     void func(int) {}

then Derived::func is not virtual because it does not match the 
signature from Base::func.  Instead you will be left with an abstract 
class because Base::func is pure-virtual so it must be defined in 
Derived to make it a concrete type.


More information about the gccxml mailing list