动态转换抛出指针不是 std::__non_rtti_object

dynamic cast throws pointer is not std::__non_rtti_object(动态转换抛出指针不是 std::__non_rtti_object)
本文介绍了动态转换抛出指针不是 std::__non_rtti_object的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到了 dynamic_cast 的问题.我刚刚编译了我的项目并在调试模式下测试了所有东西,然后我尝试在发布模式下编译它,我已经从调试模式 exept 优化参数复制了每个配置,现在是/o2,(在调试时我将它设置为/od)项目已编译,但当它开始加载我的资源时,我在此处的代码段中遇到异常:

I'm having problem with dynamic_cast. i just compiled my project and tested every thing in debug mode and then i tried compiling it in release mode, i have copied every configuration from debug mode exept optimization parameter which is now /o2, (while debuging i set it as /od) the project compiled but when it starts loading my resources i got exception in the piece of code here :

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 ,我没有足够的声誉来添加该标签!

nothing in code changed and when I check in debugger every variable in classes is what it should be but dynamic cast is throwing std::__non_rtti_object. what am i doing it wrong? and i'm using cocos2d-x ,I didn't have enough reputation to add that tag!

推荐答案

在这种情况下,经过多次代码更改后,我发现代码优化时必须有一些错误(仍然不知道是不是编译器的错误优化或我的代码有一些问题,但它可能是我的).这个问题的主要原因是 *l 为 NULL.

In this case after many code changes I found out there has to be some bugs which show themselves when code is optimized (still don't know if it's compiler's mis optimization or my code has some problems but it's probably mine). and the main reason for that problem was with *l being NULL.

这篇关于动态转换抛出指针不是 std::__non_rtti_object的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Rising edge interrupt triggering multiple times on STM32 Nucleo(在STM32 Nucleo上多次触发上升沿中断)
How to use va_list correctly in a sequence of wrapper functions calls?(如何在一系列包装函数调用中正确使用 va_list?)
OpenGL Perspective Projection Clipping Polygon with Vertex Outside Frustum = Wrong texture mapping?(OpenGL透视投影裁剪多边形,顶点在视锥外=错误的纹理映射?)
How does one properly deserialize a byte array back into an object in C++?(如何正确地将字节数组反序列化回 C++ 中的对象?)
What free tiniest flash file system could you advice for embedded system?(您可以为嵌入式系统推荐什么免费的最小闪存文件系统?)
Volatile member variables vs. volatile object?(易失性成员变量与易失性对象?)