This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: Inheritance problem
- From: John Love-Jensen <eljay at adobe dot com>
- To: Bernhard Jung <bernhard at bernhardjung dot de>, MSX to GCC <gcc-help at gcc dot gnu dot org>
- Date: Mon, 26 Nov 2007 06:30:16 -0600
- Subject: Re: Inheritance problem
Hi Bernhard,
> In don't really understand what's going wrong, because b is of type A, so
> there should be a function void foo() to call. That'S what inheritance is all
> about. But why doesn't it work and can I change this behavior somehow?
It doesn't work because B's foo method hides A's foo method.
Add this to B:
class B : public A
{
...
using A::foo;
...
};
However, the better way to fix the problem is to change the method name of
the non-virtual method so that they do not collide.
Overloading methods is a powerful, but dangerous, capability. It should not
be used casually.
HTH,
--Eljay