如何在Visual Studio 2008中关闭RTTI [英] How to turn off RTTI in Visual Studio 2008
问题描述
我不知道其他版本,但在VS 2008即使禁用RTTI,我可以通过调用 typeid(T).name()
查询信息类型。它适用于所有类型,内部和用户创建。
I am not sure about other versions, but, in VS 2008 even with RTTI disabled I can query the information by calling typeid(T).name()
on the type. It works with all types, internal and user created.
我们的项目已禁用RTTI,但我惊讶地发现,这仍然工作。这是一个Visual Studio bug还是 / GR -
标志不够禁用它吗?这是否落入未定义的行为
的领域?如果它不是一个错误,我怎么真的把它关闭?
Our project has RTTI disabled but I was surprised to find that this still worked. Is this a Visual Studio bug or is the /GR-
flag not enough to disable it? Does this fall into the realm of undefined behavior
? If it is not a bug, how do I really turn it off?
推荐答案
是否可能在表达式中使用 typeid
在编译时是已知的?如果是这样,您将绕过RTTI的运行时方面。从 typeid
的Microsoft文档:
Is it possible that you used typeid
on an expression whose type is known at compile time? If so you would bypass the "run-time" aspect of RTTI altogether. From the Microsoft documentation on typeid
:
如果表达式既不是指针,引用对象的基类
,结果是表示表达式的
静态类型的type_info引用。表达式的静态类型将
引用为表达式的类型,因为它在编译时是已知的。执行
语义在评估
表达式的静态类型时被忽略。
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.
这篇关于如何在Visual Studio 2008中关闭RTTI的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!