This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
Re: c++/3400: doesn't compile simple hierarchy with overlaoding
- To: <volker dot reichenberger at iwr dot uni-heidelberg dot de>
- Subject: Re: c++/3400: doesn't compile simple hierarchy with overlaoding
- From: "Artem Khodush" <artem at duma dot gov dot ru>
- Date: Tue, 26 Jun 2001 11:56:20 +0400
- >Received: from artem by mailsrv.duma.gov.ru (SMI-8.6/SMI-SVR4)id MAA17631; Tue, 26 Jun 2001 12:00:41 +0400
- Cc: <gcc-gnats at gcc dot gnu dot org>, <gcc-bugs at gcc dot gnu dot org>
- References: <20010625110648.30817.qmail@sourceware.cygnus.com>
>
> class A {public: void a() {};};class B: public A {public: void a(int n) {};};int main(void){ B b; b.a(); return 0;}
>
> I get the error message:
>
> test.cc: In function `int main()':
> test.cc:15: no matching function for call to `B::a ()'
> test.cc:8: candidates are: void B::a(int)
>
> I believe the code is correct (so do all my colleagues).
Nope. See the quote from the c++ standard below. In GCC 3.0,
you can fix the code by putting
using A::a();
into the class B.
13.2 Declaration matching [over.dcl]
1 Two function declarations of the same name refer to the same function
if they are in the same scope and have equivalent parameter declara-
tions (_over.load_). A function member of a derived class is not in
the same scope as a function member of the same name in a base class.
[Example:
class B {
public:
int f(int);
};
class D : public B {
public:
int f(char*);
};
Here D::f(char*) hides B::f(int) rather than overloading it.
void h(D* pd)
{
pd->f(1); // error:
// D::f(char*) hides B::f(int)
pd->B::f(1); // ok
pd->f("Ben"); // ok, calls D::f
}
--end example]