Sign in to follow this  
vbuser1338

dynamic_cast problems

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
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

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this