gpt4 book ai didi

c++ - 什么时候在没有 RTTI 的情况下编译 c++ 会导致问题?

转载 作者:IT老高 更新时间:2023-10-28 13:59:01 25 4
gpt4 key购买 nike

我正在使用 gcc 的 -fno-rtti标志编译我的 C++ 没有运行时类型信息。

假设我没有使用 dynamic_cast<>typeid() ,有什么可能导致我以后遇到问题吗?

最佳答案

由于您的问题是针对 GCC 的,因此您应该仔细查阅您正在使用的版本的文档。 GCC 4.5.2 的文档说明如下。从我的阅读中可以看出,如果你避免使用 dynamic_cast 和 typeid,你应该没问题。也就是说,我对 -fno-rtti 没有个人经验。也许您可能想详细说明为什么要使用 -fno-rtti。

-fno-rtti
Disable generation of information about every class with virtual functions for use by the C++ runtime type identification features (dynamic_cast and typeid). If you don't use those parts of the language, you can save some space by using this flag. Note that exception handling uses the same information, but it will generate it as needed. The dynamic_cast operator can still be used for casts that do not require runtime type information, i.e. casts to void * or to unambiguous base classes.

No RTTI but still virtual methods 上讨论了虚函数和 RTTI 之间的关系。 .简短的版本是没有 RTTI 的虚函数应该没问题。

关于c++ - 什么时候在没有 RTTI 的情况下编译 c++ 会导致问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4486609/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com