when accessing foo() of “base” using derived class’s object.
#include <iostream>
class base
{
public:
void foo()
{
std::cout<<"\nHello from foo\n";
}
};
class derived : public base
{
public:
void foo(int k)
{
std::cout<<"\nHello from foo with value = "<<k<<"\n";
}
};
int main()
{
derived d;
d.foo();//error:no matching for derived::foo()
d.foo(10);
}
how to access base class method having a method of same name in derived class.
the error generated has been shown.
i apologize if i am not clear but i feel i have made myself clear as water.
thanks in advance.
You could add
using base::footo your derived class:Edit: The answer for this question explains why your
base::foo()isn’t directly usable fromderivedwithout theusingdeclaration.