The following code will call the function F from class B, but can someone please explain to me why is that. Is it possible that methods from class B overload the ones from class V (because B is inherited from V)? Thanks in advance.
#include <iostream>
using namespace std;
class V{
public:
void f(){ x+=2; cout << "V:"<< x;};
int x;
};
class B: public virtual V{
public:
void f(){ x+=3; cout << "B:"<< x;};
int x;
};
class D: public B, virtual public V{
public:
void g(){ x++; f(); }
};
void main(){
D ins;
ins.x = 1;
ins.g();
}
B::f()hides the methodV::f(), this is known as function hiding.Good Read:
What’s the meaning of, Warning: Derived::f(char) hides Base::f(double)?