I'm sure this is OOP 101 (maybe 102?), But I am having trouble understanding how to do this.
I am trying to use one function in my project to get different results based on which object is passed to it. From what I read today, I think I have the answer, but I hope that someone here can lift me up a bit.
class A
{
virtual void DoThis() = 0;
};
class B : public A
{
void DoThis()
};
void DoStuff(A *ref)
{ref->DoThis();}
int main()
{
B b;
DoStuff(&b);
}
Moreover, if I have several base-based classes, can I pass any Derived class to functions DoStuff(A *ref)and use virtual files from the base?
Am I doing it right or am I from here without reason?
source
share