Jump to content
  • Advertisement
Sign in to follow this  
discodowney

Virtual functions

This topic is 2666 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

So i have a class that loads in a mesh called meshModel. Then i have the player and enemy classes that are inherited from that. In each of the inherited classes i need a function called updateMatrices. But each will be a small bit different so i cant just put it in the meshModel class. I will have a vector holding all the models in the game (player and enemies). They are added to the vector like:


theShip = new spaceShip(Device, "bigship1.x", D3DXVECTOR3 (0.0f, 7.0f, 0.0f));
meshes.push_back(theShip);

But i want to do something like a for loop for all models in the vector like

meshModel->updateMatrices()

So how does this work then? Do i make the function in meshModel virtual and then implement it in the inherited methods? But i think if i do it this way, when the function is called it'll call the meshModel updateMatrices.
So is there a way for me to do this? To have the meshModel vector but call the updateMatrices function from either the player or enemy?

Share this post


Link to post
Share on other sites
Advertisement
Making the function virtual will do it, as long as your vector stores pointers to base classes and you fill it with pointers to derived classes.

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!