Kinda long-winded, but here goes:
It seems as though I''ve hit another obstacle in my game *gasps around the table*. Only this time, I know what the problem is. I just need to know how to work around it.
I''ve got a class, let''s call it CClass. It has a virtual function, let''s call it MyVirtualFunction() (notice the innovative names I''m using).
Surprisingly enough, I do know how to declare virtual functions and what they are used for, so don''t worry about that.
Now, I have a class derived from CClass, let''s call it CChildClass. It overrides the virtual function MyVirtualFunction(), with its own virtual function of the same name. The parameter list is the same.
All right, if you''re with me so far, I now have a CClass pointer, shall we call it *MyPointer.
Now, during the function that MyPointer is declared in, one of the following will happen. Either:
MyPointer = new CClass;
or
MyPointer = new CChildClass;
This works great, as this is one of the beauties of pointers. However, in this same function, I call MyPointer->MyVirtualFunction().
If MyPointer points to a CClass object, I want it to call CClass::MyVirtualPointer(). However, if it points to a CChildClass object, I want it to call CChildClass::MyVirtualPointer().
Which I thought should work because the function is virtual. This, as it happens, is my own undoing.
Because *MyPointer is a pointer of type CClass, it only calls CClass::MyVirtualFunction() regardless of wether it is pointing to a CClass object or a CChildClass object.
So what do I do? Do I make MyVirtualFunction() a normal member function instead of virtual in both classes? Just one? Do I leave it virtual, but use some other pointer? Do I just call it differently?
Your help is appreciated in advance, as always.
The_Minister
1C3-D3M0N Interactive