Hello,
I've confused myself a bit with virtual functions. I know they're useful when you want to call the parents function via casting the class to it's parent, but I've found myself scratching my head on few cases.
So... Lets say I have a parent Class P and a child class C. P has a function setupBuffer() and is called by the constructor. I want the child class to overide it such that when the parent calls setupBuffer() it calls the child's version. Should either be virtual?
Another situation is when I want the child class always to be called even if casted as the parent.
In what cases would doing:
void c::func()
{
p::func();
}
not work, or will it always work regardless of virtual being tagged to function?
What's the difference between having the parent func being virtual and when both are virtual? Also, if the child was only virtual, would that do anything (in relationship to the parent)?