Warning about overrides hiding base class methods ?

Matthew Jones matthewjones@vw1600e.org.uk
Mon Aug 1 10:50:00 GMT 2005


I am getting an odd error from gcc 3.4.3.
The example code below generates the following error:

  main.cpp:6: warning: `virtual void A::fn(float&)' was hidden
  main.cpp:19: warning:   by `virtual void Y::fn(int&)'

Why ? A::fn(float) should not be hidden, because Y::fn(int) and its inherited
Y::fn(float) have different signatures.
If Y had a non-virtual fn(float), that *would* hide the A::fn(float) but not
A::fn(int).

I know that usually gcc warnings have a very good explanation behind them, but
this time I can't see what it is trying to tell me. Can someone explain ?!

TIA.

---- code ----

class A
{
public:
    virtual void fn(int &) {}
    virtual void fn(float &) {}
};

class X : public A
{
public:
    virtual void fn(int &) {}
    virtual void fn(float &) {}
};

class Y : public A
{
public:
    virtual void fn(int &) {}
};

---- end of code ----

--
Matthew JONES
http://www.tandbergtv.com/



More information about the Gcc-help mailing list