If I have a hierarchy of C++ classes where the base class has a member function that is declared as virtual, but derived classed do not declare that function as virtual, how far into the class hierarchy does the virtualization carry. For example, given the code is the return value of MyFunc2 well defined?
class A
{
public:
virtual int x() { return 1; }
}
class B : public A
{
public:
int x() { return 2; }
};
class C: public B
{
public:
int x() { return 3; }
};
int MyFunc1(f &A)
{
return f.x();
}
int MyFunc2(f &B)
{
return f.x();
}
int MyFunc3()
{
C c;
return MyFunc1(c);
}
int MyFunc4()
{
C c;
return MyFunc2(c);
}
From similar question here, it would appear that the virtual characteristic is propagated forward to all classes once it is virtual in the base class, but I'm wondering how well defined this is, specifically is B.x() virtual by implication of being derived from A.