K
keith
Hi all, I'm getting confused again, so someone please take pity and
explain. I've got something like this:
class Base
{
void do_work(string&, string&, int&);
};
class Derived : public Base
{
void do_work(char*, char*, int&);
};
int main()
{
Derived MyObj;
string sString, bString;
MyObj.do_work(aString, bString, 123);
}
This gives a compile-time error that basically says
no matching function for call to `Derived::do_work(string&, string&,
int)'
candidates are: void Derived::do_work(char*, char*, int&)
Why does the compiler not use the matching function from the Base
class? I can work around it by doing something like this:
int main()
{
Base* ptr = new Derived();
string aString, bString;
ptr->do_work(aString, bString, 123);
delete ptr;
}
but that seems to sort of defeat the purpose of inheritance, to my
newbie eyes at least.
explain. I've got something like this:
class Base
{
void do_work(string&, string&, int&);
};
class Derived : public Base
{
void do_work(char*, char*, int&);
};
int main()
{
Derived MyObj;
string sString, bString;
MyObj.do_work(aString, bString, 123);
}
This gives a compile-time error that basically says
no matching function for call to `Derived::do_work(string&, string&,
int)'
candidates are: void Derived::do_work(char*, char*, int&)
Why does the compiler not use the matching function from the Base
class? I can work around it by doing something like this:
int main()
{
Base* ptr = new Derived();
string aString, bString;
ptr->do_work(aString, bString, 123);
delete ptr;
}
but that seems to sort of defeat the purpose of inheritance, to my
newbie eyes at least.