My C++code is as follows:
#include<iostream>
using namespace std;
class A
{
public:
virtual void f(int i)
{
cout << "A f(int)!" << endl;
}
void f(int i, int j)
{
cout << "A f(int, int)!" << endl;
}
};
class B : public A
{
public:
virtual void f(int i)
{
cout << "B f(int)!" << endl;
}
};
int main()
{
B b;
b.f(1,2);
return 0;
}
at compile time I get:
g++ -std=c++11 file.cpp
file.cpp: In function βint main()β:
file.cpp:29:9: error: no matching function for call to βB::f(int, int)β
file.cpp:29:9: note: candidate is:
file.cpp:20:16: note: virtual void B::f(int)
file.cpp:20:16: note: candidate expects 1 argument, 2 provided
When I tried to use the override after B f (int), I got the same error.
Is it possible to override only one method in C ++? I was looking for sample code using overridethat will compile on my machine and have not found it yet.
Noich source
share