+ 4
Whats wrong with this C++ code...???
Code is correct but it gives compile time error... There is inheritance so base class method must be inherited in derived class which are public and protected but in this case that not happened. https://code.sololearn.com/cAQidii984bD/?ref=app
4 Answers
+ 4
There is inheritance so base class method must be inherited in derived class which are public and protected but in this case that not happened.
method of class A
void f(int x)
{
cout<<x;
}
must be inherited in class B.
//
if I removed method of class B i.e.
void f()
{
cout<<"b\n";
}
Then object of class B able to call method of class A
I.e.
B ob;
ob.f(7); // No error
it works correctly.
+ 3
Class Bâs method doesnât take arguments, so the compiler doesnât know what to do with the 7
0
add this
void f(int x)
{
cout<<x;
}
after line 26
this function will be executed if you pass arguments with f
0
This is standart behavior. If derived class declares method with the same name as a method defined by base class, derived class' method hides base class' one.
Solution:
Add after public in class B:
using A::f;
or when call method
ob.A::f(7);