c++ - reinterpret_cast 充当 dynamic_cast

标签 c++ visual-c++

我的代码是这样的:

void some_func(void *source)
{
    ...
    double *casted = reinterpret_cast<double *>(source);
    ...
}

这会导致 std::__non_rtti_object 异常。根据堆栈跟踪,它是从 __RTDynamicCast 引发的,这是(据我所知)dynamic_cast 的 MSVC 实现。

此异常应该发生在 dynamic_cast 中,因为指针来自外部库(可能在没有/GR 的情况下编译)并指向具有多个 double 的结构。但我不希望 reinterpret_cast 会这样。它不应该只是改变指针的类型,而不进行任何检查吗?

注意事项:

  • 我的编译器是 msvc120 (MS Visual Studio 2013)
  • 项目使用/GR 编译(启用运行时类型信息)
  • 指针“源”来自外部库(可能在没有/GR 的情况下编译)
  • 我也试过 static_cast 得到了同样的结果

最佳答案

不可复制。

Ah, i tried to rebuild whole project with all additional libraries and the problem disappeared. Seems strange, because I never had a code using dynamic_cast, so don't know what caused this. Also I already tried to rebuild that project only (without other dlls) before. Anyway, thanks for all help. -- OP

关于c++ - reinterpret_cast 充当 dynamic_cast,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20503708/

相关文章:

c++ - 屏幕任意位置的工具提示--vc++ Express Edition

c++ - 执行示例项目时出现 libvlc-qt 错误

c++ - 调用专用模板函数时强制编译时错误

c++ - 全局声明 Boost ptime

c++ - 在 strlwr() 中使用字符串数据类型

c++ - 在 d2i_RSAPrivateKey_fp() 中崩溃

c++ - 模板类构造函数问题——为 multidim 数组设计容器

c++ - 如何制作全屏滚动消息框或窗口?

c++ - 我应该如何指定指针成员的构造函数参数的常量性

c++ - 加快双倍到有理数的转换