g++ 2.95.1/2 inheritance bug
Martin v. Loewis
martin@loewis.home.cs.tu-berlin.de
Thu Feb 10 23:36:00 GMT 2000
> 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
More information about the Gcc-bugs
mailing list