Jump to content
  • Advertisement
Sign in to follow this  
vbuser1338

dynamic_cast problems

This topic is 4735 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

I have a system of class derived from a common base class so that they can be stored in a vector of pointers to game objects. Here is the basic system: CObject CCollision_Object CMesh_Collision_Object CEnemy I have the enemies attached to the level and I have a RenderChildren() function to render the children. The problem is trying to find a way to see if I can cast the CObject pointer correctly to a CMesh_Collision_Object that can be rendered. It works if I cast it to a CEnemy object it works but that is not that great because I want to reuse this so thats not a very good way. This is what I am trying to do.
[Source]
void CMesh_Collision_Object::RenderChildren() {
    // Render the children
    std::list<CObject*>::iterator i;
    CStatic_Model *mod;
	CMesh_Collision_Object *mesh;
    for(i = children.begin();i != children.end();++i) {	
        // Make sure its a renderable object
        //if(mod = dynamic_cast<CStatic_Model*>(*i)) 
           // mod->Render();	// Render
		if(mesh = dynamic_cast<CMesh_Collision_Object*>(*i)) {
			CLog::Log("yes\n");
			mesh->Render();		// Render
		}
    }
}
[/Source]
Is there a way to see if the Object pointer in the vector is of type CMesh_Collision_Object or is derived from it so that it can be rendered? Thanks, vbuser

Share this post


Link to post
Share on other sites
Advertisement
Sorry it was my problem. I am having this problem on my IDE where it compiles the new files but links old ones which causes somethings to work or makes you mad why something is not working because it is using old files during linking. I really have to figure out why this is happening. I did a clean on my project and rebuilt everything and now it works fine.

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!