This is the mail archive of the gcc-help@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]
Other format: [Raw text]

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


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