我在使用 dynamic_cast 时遇到问题。我刚刚编译了我的项目并在 Debug模式下测试了所有东西然后我尝试在 Release模式下编译它,我已经从 Debug模式复制了每个配置除了优化参数现在是/o2,(调试时我将它设置为/od)项目已编译,但当它开始加载我的资源时,我在此处的代码段中遇到异常:
for(int j = 1; j < i->second->getParametersNumber();j++)
{
CCTMXTiledMap* temp = CCTMXTiledMap::tiledMapWithTMXFile(i->second->As<string>(j).c_str());
CCTMXLayer* ret = NULL;
for(NSMutableArray<CCNode*>::NSMutableArrayIterator l=temp->getChildren()->begin();!ret && l!=temp->getChildren()->end();l++)
ret = dynamic_cast<CCTMXLayer*> (*l);
t1.first = ret;
templates[i->first].second.push_back(t1);
templates[i->first].second.back().first->retain();
}
代码中没有任何变化,当我检查调试器时,类中的每个变量都是它应该的,但动态转换正在抛出 std::__non_rtti_object。我做错了什么?我正在使用 cocos2d-x,我没有足够的声誉来添加该标签!
最佳答案
CCNode
有虚函数吗? temp->getChildren()->begin() 的所有元素都是 CCNode
吗? temp->getChildren()
是否返回引用?后者尤其隐蔽:您同时调用了 temp->getChildren()->begin()
和 temp->getChildren()->end()
。如果 getChildren()
返回一个拷贝,您将获取一个拷贝的 begin
和另一个拷贝的 end
。
关于c++ - 动态转换抛出指针不是 std::__non_rtti_object,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5582874/