Inheritance problem
Bernhard Jung
bernhard@bernhardjung.de
Mon Nov 26 12:30:00 GMT 2007
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
More information about the Gcc-help
mailing list