I am experiencing a problem where a derived class does not have it's own version of a function called when it is called from a base class pointer. To better explain the classes are defined as below
Class Foo
{
public:
Foo();
virtual ~Foo();
virtual void Event();
}
//-----------------------
Class FooBar : public Foo
{
public:
FooBar();
virtual void Update() = 0;
virtual void Draw() = 0;
}
//-----------------------
Class FinalFoo : public FooBar
{
public:
FinalFoo();
void Update();
void Draw();
void Event();
}
There are other classes similar to FinalFoo. So I attempt to call Event on a pointer to a Foo object expecting that it would call the derived implementation. However, it would appear that it calls the base class version and that is all
FinalFoo* myThing = new FinalFoo();
Foo* baseThing = myThing;
baseThing->Event(); // I expected this to call FinalFoo::Event()
FinalFoo myThing; Foo &baseThing = myThing;FinalFoo::Event(). However, the example is clearly not the original code (it contains a few errors, e.g., missing semicolons after your class definitions) and there are subtle changes in the signature which may prevent the function you think is overriding the base class virtual function from doing so. If you have C++11 addoverrideafter each overriding function and the compiler will tell you if it is, indeed, an override!Eventdoes get called for the FinalFoo object,myThing? Also, what happens if you makeEventinFooa pure virtual by adding= 0?