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); }

25th Aug 2016, 5:41 AM
Lekhraj Singh
Lekhraj Singh - avatar
4 Réponses
+ 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.
25th Aug 2016, 9:01 AM
James
James - avatar
+ 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.
25th Aug 2016, 11:41 AM
James
James - avatar
0
James, how to check that function is overridden?
25th Aug 2016, 11:34 AM
Lekhraj Singh
Lekhraj Singh - avatar
0
thanks james
25th Aug 2016, 11:51 AM
Lekhraj Singh
Lekhraj Singh - avatar