This is the mail archive of the gcc-bugs@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]

Re: g++ 2.95.1/2 inheritance bug


> Obviously, the operator>> taking the function pointer argument is
> not properly inherited from class myinsuper to class
> myinstream. When I copy the definition line from class myinsuper to
> class myinstream, the code is compiled correctly.

Thanks for your bug report. This is not a bug in g++, but in your
code. If a derived class defines an operator or a method with a
certain name, all methods and operators from the base class with the
same name are hidden. Please see any C++ book for details, or ask on
comp.lang.c++.moderated.

In Standard C++, you can solve this by writing

class myinstream : public myinsuper
{
    public:

    myinstream() : myinsuper() {}

    using myinsuper::operator>>;
    virtual myinsuper& operator>>(bool &b)
    {
        return *this;
    }
};

Due to a bug listed in bugs.html, this does not work in g++. To
work-around that bug in g++, you can write

class myinstream : public myinsuper
{
    public:

    myinstream() : myinsuper() {}

    virtual myinsuper& operator>>(myinsuper& (*f)(myinsuper*)) 
       { return myinsuper::operator>>(f);}
    virtual myinsuper& operator>>(bool &b)
    {
        return *this;
    }
};

Hope this helps,
Martin

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