0
why this program show compile error? #include<iostream> using namespace std; class a{ public: int f(){cout<<3;} int f(int a){cout<<a;} }; class b:public a { public: int f(){cout<<5;} }; int main() { b obj; obj.f(7); }
4 Respuestas
+ 1
Because the f function is overridden. When you do this, the other classes function and it's overloaded function become hidden, leaving only the b classes function as an option.
+ 1
You can test that it is in fact overridden by removing the int inside obj.f(); You'll see that it outputs 5 instead of 3.
0
James, how to check that function is overridden?
0
thanks james