c – 如何在Visual Studio 2008中关闭RTTI

我不确定其他版本,但是,在VS 2008中,即使禁用了RTTI,我也可以通过调用类型上的typeid(T).name()来查询信息.它适用于所有类型,内部和用户创建.

我们的项目已禁用RTTI,但我惊讶地发现这仍然有效.这是一个Visual Studio错误还是/ GR-标志不足以禁用它?这是否属于未定义行为的范畴?如果它不是一个bug,我该怎么把它关掉?

解决方法:

是否有可能在类型在编译时已知的表达式上使用typeid?如果是这样,你将完全绕过RTTI的“运行时”方面.从关于typeid的Microsoft文档:

If the expression is neither a pointer nor a reference to a base class
of the object, the result is a type_info reference representing the
static type of the expression. The static type of an expression refers
to the type of an expression as it is known at compile time. Execution
semantics are ignored when evaluating the static type of an
expression.

上一篇:C++ RTTI


下一篇:Jmter如何提取响应中的返回值并保存到文件中