我的代码是这样的:
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/