My C++
code is as follows:
#include<iostream>
using namespace std;
class A
{
public:
virtual void f(int i)
{
cout << "A's f(int)!" << endl;
}
void f(int i, int j)
{
cout << "A's f(int, int)!" << endl;
}
};
class B : public A
{
public:
virtual void f(int i)
{
cout << "B's f(int)!" << endl;
}
};
int main()
{
B b;
b.f(1,2);
return 0;
}
during compilation 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 override after B's f(int), I got the same error.
Is it possible in C++ to override only 1 method? I've been searching for a code example using override
that will compile on my machine and haven't found one yet.