dynamic_cast problems

Started by
0 comments, last by vbuser1338 18 years, 4 months ago
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
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.

This topic is closed to new replies.

Advertisement