Why provide a declaration in the derived class for a virtual base class function
Code:
#include <iostream>
using namespace std;
class X
{
public:
X(){}
virtual void f1()
{
cout << "In Base" << endl;
}
void f2()
{
cout << "F2 in Base" << endl;
}
};
class Y : public X
{
public:
Y(){}
// void f1(); If I uncomment this.. it works.. but why does it demand this declaration.
};
void Y::f1()
{
cout << "F1 In Derived" << endl;
// Since f1() is a virtual function in base,
// why does it demand a declaration in derived too????
}
int main()
{
Y ob;
ob.f1();
return 0;
}
Error Message:
"test.C", line 29: Error: f1() is not a member of Y.
1 Error(s) detected.