overriding some of the methods with the same name yields an error
Hi
There is a question I'm trying to solve for some time without any
success:
When a base class has several methods with the same name (overloaded)
and a derived class overrides one or some of the methods all other (not
overridden) methods are hidden as well.
for example:
#include <iostream>
using namespace std;
class B
{
public:
virtual void foo(const char* arg)
{cout<<"B::foo(const char*):"<<arg<<endl;}
virtual void foo(int arg)
{cout<<"B::foo(int):"<<arg<<endl;}
};
class D :public B
{
public:
virtual void foo(int arg)
{cout<<"D::foo(int):"<<arg<<endl;}
};
int main()
{
D* d = new D();
d->foo("hello");
d->foo(3);
delete d;
return 0;
}
this example refuses to compile on account of the "hello" char[6] not
able to be converted to an int. I tried it on g++ and VC6 and both did
the same so I guess it's not a compiler bug but rather a standard rule
or direction.
BTW when d's type is replaced to a B* the program runs OK.
my question is why am I seeing this behavior and what is the logic
behind this?
Thanks
Oren
---
[ comp.std.c++ is moderated. To submit articles, try just posting with ]
[ your news-reader. If that fails, use mailto:std-c++@ncar.ucar.edu ]
[ --- Please see the FAQ before posting. --- ]
[ FAQ: http://www.comeaucomputing.com/csc/faq.html ]