Static_cast error in Wiki code

User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Static_cast error in Wiki code

Post by SynapticBytes »

I'm trying to implement collision responses as per the wiki, and have taken the following code snippet from the collision interface demo

Code: Select all

	int numManifolds = collisionWorld->getDispatcher()->getNumManifolds();
	for (i=0;i<numManifolds;i++)
	{
		btPersistentManifold* contactManifold = collisionWorld->getDispatcher()->getManifoldByIndexInternal(i);
		btCollisionObject* obA = static_cast<btCollisionObject*>(contactManifold->getBody0());
		btCollisionObject* obB = static_cast<btCollisionObject*>(contactManifold->getBody1());
	
		int numContacts = contactManifold->getNumContacts();
		for (int j=0;j<numContacts;j++)
However, when I put it in my code, it complains about the static_cast saying it can't cast from const to non-const. If I put const_cast, it works.

I'm wondering why the static_Cast which is in the demo, is giving compile errors in my code, and whether I am OK to use const_cast or not?

Thanks.
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: Static_cast error in Wiki code

Post by Erwin Coumans »

You should be using a const_cast, it should be fixed in the demo.

Some recent work made the collision object 'const' and this propagated into the API.
User avatar
SynapticBytes
Posts: 74
Joined: Thu Feb 10, 2011 8:27 pm

Re: Static_cast error in Wiki code

Post by SynapticBytes »

Erwin Coumans wrote:You should be using a const_cast, it should be fixed in the demo.

Some recent work made the collision object 'const' and this propagated into the API.
Cool thanks. This is also in the Wiki article on how to do collision response, so needs fixing there too.