+ 4
Inheritance code reusability
In below code, why error of compilation is occurring instead of inheritance? class A { public: int f() {} int f(int a) {} }; class B : public A { public: int f() {} }; int main() { B b; b.f(7);// this causes error... return 0; } I believe method from A class should be available due to inheritance and it should build.
5 Respuestas
+ 2
It is but while you dont declare another method with same name (dont import params and return type) else you effectively hide base methods and only mode for call Base method from derived instance is:
b.A::f(7)
+ 1
does this mean if I don't write a method int f() in class B, code will compile properly?
+ 1
correct... conclusion is that either define all or not a single function from all overloaded function of base class in derived class... thank you so much
+ 1
👍👍👍👍
0
Try it 😉