I was asked this question in an interview and I was unsure of the behaviour in the following case :
class A
{
virtual fun1(){...}
virtual fun2(){...}
};
class B : public A
{
virtual fun1(){...}
virtual fun2(){...}
};
Now if,
A* AObj = new A;
B* BObj = (B*) AObj;
Does BObj
have access to B's methods because of the virtual keyword or does it not because it's pointing to an object of AObj
?
Can someone help me with how exactly downcasting affects access also ?