So suppose I have:
Class A
{
void A::DoSomething();
A::A()
};
Class B : public A
{
void B::DoSomething();
B::B()
}
Class C : public A
{
void C::DoSomething();
C::C()
}
B obj1;
C obj2;
void RemoveObjectFromListOrSomethingSimiliar(A objToLookFor)
{
//assuming you found the object, how would you call the top-level DoSomething() (for example B::DoSomething() ) instead of the A::DoSomething()?
}
I’m not sure if that makes sense
[EDIT]
Ok, so that’s kinda working. Though it’s still redirecting to the base method, which confuses me.
B obj1;
c obj2;
AList.push_back(obj1);
AList.push_back(obj2);
//later, in another method:
A objInBack = AList.back();
objInBack.DoSomething();
AList.pop_back();
The objInBack refers to the A-level of the class structure and subsequently calls that level of DoSomething(). I’ve changed A’s methods to virtual, so is there some way to explicitly define the level of execution or?
I’m not sure I got your question right, but I guess what you need is dynamic binding.
Here is an example based on your pseudocode.
The output would then be: