could someone explain the reason why the following simple codes does not compile? Thanks!
#include <iostream>
using namespace std;
class Base {
public:
Base () {}
virtual void f() {cout << 1;}
virtual void f(int i) {cout << i;}
};
class Derived: public Base {
public:
Derived() {}
void f() {cout << 3;}
};
int main() {
Derived d;
d.f(7); // Compilation error
return 0;
}
prog.cpp: In function 'int main()':
prog.cpp:19:8: error: no matching function for call to 'Derived::f(int)' d.f(7); //Compilation Error
^
prog.cpp:13:7: note: candidate: void Derived::f()
void f() {cout << 3;}
^
prog.cpp:13:7: note: candidate expects 0 arguments, 1 provided