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]

Inheritance problem


Hi,

on my linux system the following code doesn't compile:

class A
{
public:
    void foo() {}
    virtual void foo( int i ) {}
};

class B : public A  
{
public:
    virtual void foo( int i ) {}
};

int main()
{
    B b;
    b.foo();
    return 0;
}

It gives me a error message saying, that there is no function B::foo() but a 
function virtual void B::foo(int).

My gcc version is: g++ (GCC) 4.1.3 20070929 (prerelease) (Ubuntu 
4.1.2-16ubuntu2)

This also happens on the windows system of a friend, but he can call 
b.A::foo(), which doesn't work for me.

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?

Regards
Bernhard


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