This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: g++ 2.95.1/2 inheritance bug
- To: Karsten dot Otto at xtradyne dot de
- Subject: Re: g++ 2.95.1/2 inheritance bug
- From: "Martin v. Loewis" <martin at loewis dot home dot cs dot tu-berlin dot de>
- Date: Fri, 11 Feb 2000 08:30:35 +0100
- CC: gcc-bugs at gcc dot gnu dot org
- References: <200002091004.LAA04565@dolphin.xtradyne.de>
> 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