从'const b2Shape *'动态投射到'b2PolygonShape *'会抛弃限定符?

时间:2012-09-03 17:51:03

标签: ios casting box2d polygon shape

我只是尝试从b2PolygonShape创建b2Shape,但我收到的错误是:Dynamic-cast from 'const b2Shape*' to 'b2PolygonShape*' casts away qualifiers

这是我的代码:

const b2Shape *s = fix2.shape;
b2PolygonShape *p = dynamic_cast<b2PolygonShape*>(s);

我做错了什么?

1 个答案:

答案 0 :(得分:1)

编译器抱怨的是const限定符。解决方案是 将p声明为const b2PolygonShape的指针:

const b2PolygonShape *p = dynamic_cast<const b2PolygonShape*>(s);