This is the mail archive of the gcc-help@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem with virtual const


Hi Pierre,

Since the two functions have the same name (even though different
signatures), B will hide A's other g().

Here's how you tell the compiler that you actually want A's g() to be
visible in B:

class B : public A
{
  public:
    virtual ~B() {}
    virtual int g(int x) const {return x;}
    using A::g;
};

This behavior is in the language intentionally.  The rationale being (if I
recall correctly) is that for non-trivial projects it is desirable for the
compiler to flag situations where possible changes to the parent class
during on-going development may not yet be reflected in the child class.

HTH,
--Eljay


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]