Inheritance problem

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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 of Archives]     [Linux C Programming]     [Linux Kernel]     [eCos]     [Fedora Development]     [Fedora Announce]     [Autoconf]     [The DWARVES Debugging Tools]     [Yosemite Campsites]     [Yosemite News]     [Linux GCC]

  Powered by Linux