小编Dea*_*kle的帖子

为什么Objective-C++中的dynamic_cast在调试中成功但在发布时失败?

我在最新版本的Xcode(编写本文时为9.4.1)中构建了一个C++框架,我使用的是Objective-C++代码,同样在Xcode中.我需要执行dynamic_cast从一种指针类型到另一种指针类型.但是,dynamic_cast它仅适用于Debug构建,并且不适用于Release构建.我是否缺少某些东西或了解dynamic_castObjective-C++中如何使这个样本失败?

C++框架

TestClass.hpp

class Parent {
    public:
    // https://stackoverflow.com/a/8470002/3938401
    // must have at least 1 virtual function for RTTI
    virtual ~Parent();

    Parent() {}
};

class Child : public Parent {
public:
    // if you put the implementation for this func 
    // in the header, everything works.
    static Child* createRawPtr(); 
};
Run Code Online (Sandbox Code Playgroud)

TestClass.cpp

#include "TestClass.hpp"

Parent::~Parent() {}

Child* Child::createRawPtr() {
    return new Child;
}
Run Code Online (Sandbox Code Playgroud)

Objective-C++命令行应用程序

main.mm

#import <Foundation/Foundation.h>
#import <TestCastCPP/TestClass.hpp>

int main(int argc, const char * …
Run Code Online (Sandbox Code Playgroud)

c++ objective-c++

6
推荐指数
1
解决办法
227
查看次数

标签 统计

c++ ×1

objective-c++ ×1