Original Post
Hello, This issue has got me stuck for really long and I feel like giving up. I have a BaseObject class which is meant to be simple and light, and other classes derive from this one. For simplicity: The subclasses are Human, Alien and Car. I have implemented mounting of Humans to Cars.
// Car.cpp
Human* mountList; // Humans mounted to this object.
// Human.cpp
Car* mountParent; // The car which this human is mounted to.
// Human.cpp (Pseudo Code)
function Human::updateMove( move )
{
if ( isMounted() )
{
// We are mounted, follow the parent.
pos = mountParent -> getMountObjectPosition();
setPosition ( pos );
}
else
{
setPosition ( move );
}
}
This works great for Humans. The problem is, I cannot mount Aliens because the list expects Human pointers. I tried using BaseObject instead in the list, but BaseObject does not have the function getMountObjectPosition() which I am calling above and I would have to move it, negating the 'simpleness' of the base class. I guess I could static_cast from BaseObject to Human/Alien, but would that be wise in a function which is called every 32 ms, for *each* object? Perhaps there is no performance overhead with static_cast, unlike dynamic_cast? Any help will be greatly appreciated! If we can reach a solution I am willing to send $20 as a thank you via PayPal.