GreenDragon
I want use method of base class when my derived class has method with the same name but with different arguments.
If I just try to call base method I've got a compile time error:
> *.cpp: In function 'int main()':
> *.cpp:25:11: error: no matching function for call to 'Derived::foo()'
> p1.foo();
> ^
> *.cpp:13:7: note: candidate: 'void Derived::foo(int)'
> void foo(int c)
> ^~~
> *.cpp:13:7: note: candidate expects 1 argument, 0 provided
> Compilation failed.
Here is code:
#include <iostream>
struct Base
{
void foo()
{
std::cout<<"Base foo\n";
}
};
struct Derived : public Base
{
void foo(int c)
{
(void)c;
std::cout<<"Derived foo";
}
};
int main()
{
Derived p1;
p1.foo();
}
So how to access the base method if derived method is hiding the base one?
Top Answer
Pax
Using syntax `[OBJECT].[BASE_CLASS]::[METHOD]`
```
p1.Base::foo();
```
Try in [repl.it](https://repl.it/@paxcodes/cplusplusta1170)