Re: Virtual Method Behavior That I Don't Understand
On Jan 26, 2:26 pm, "r...@manbert.com" <r...@manbert.com> wrote:
(trouble with overriding virtual overloaded function
taking char const * and std::string)
What you are failing to understand is that in C++, if you
declare a function in a class, then it hides any functions
of the same name in any base class. You have to
explicitly bring forward the base class functions.
There are two red herrings in your code:
1. polymorphism has nothing to do with the problem
2. A function taking std::string can be called with a
parameter of type (char const *), because it has a
non-explicit constructor that takes such a parameter.
Here is a simpler example:
class Base
{
void f() { std::cout << "base::f(void)\n"; }
void f(int) { std::cout << "base::f(int)\n"; }
};
class Derived: public Base
{
void f(int) { std::cout << "derived::f(int)\n"; }
};
int main()
{
Derived d;
d.f(); /* error -- symbol Base::f is hidden by Derived::f */
}
To explicitly make other overloads of 'f' from the base
class visible in the derived class, insert the following
line in the derived class definition:
using Base::f;
--
[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]