warning C4541: 'dynamic_cast' used on polymorphic type 'class MyObject' with /GR-; unpredictable beh
2014-05-29 16:13
1066 查看
今天在VC6.0中使用dynamic_cast<>运算符时遇到一个莫明其妙的警告:
warning C4541: 'dynamic_cast' used on polymorphic type 'class MyObject' with /GR-; unpredictable behavior may result.
而这个警告实际上是一个严重的错误,回导致程序异常中止,可我检查发现代码上没有错误啊?! 后来上MSDN查询编译器/GR选项的含义时,终于弄清楚了这个问题。
原来这个问题是因为VC6.0编译器默认不支持C++中的RTTI,所以在编译包含dynamic_cast或者typeid运算符的程序时就会发出警告。“/GR-”选项的含义就是表示关闭“/GR”( 即Grant RTTI ) 。 解除这个警告的办法就是打开"/GR"选项或者直接在编译器参数中添加"/GR"即可。
MSDN中的全文描述如下:
/GR (Enable Run-Time Type Information)
The Enable Run-Time Type Information option (/GR) causes the compiler to add code to check object types at run time. When this option is specified, the compiler defines the _CPPRTTI preprocessor macro. The option is cleared (/GR–) by default.
To find this option in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click C++ Language in the Category box.
解决方法:
project->Settings->c/c++(catagory)->c++ language
在Enable Runtime Type Information(RTTI)前勾选。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/miyunhong/archive/2010/01/15/5193589.aspx
warning C4541: 'dynamic_cast' used on polymorphic type 'class MyObject' with /GR-; unpredictable behavior may result.
而这个警告实际上是一个严重的错误,回导致程序异常中止,可我检查发现代码上没有错误啊?! 后来上MSDN查询编译器/GR选项的含义时,终于弄清楚了这个问题。
原来这个问题是因为VC6.0编译器默认不支持C++中的RTTI,所以在编译包含dynamic_cast或者typeid运算符的程序时就会发出警告。“/GR-”选项的含义就是表示关闭“/GR”( 即Grant RTTI ) 。 解除这个警告的办法就是打开"/GR"选项或者直接在编译器参数中添加"/GR"即可。
MSDN中的全文描述如下:
/GR (Enable Run-Time Type Information)
The Enable Run-Time Type Information option (/GR) causes the compiler to add code to check object types at run time. When this option is specified, the compiler defines the _CPPRTTI preprocessor macro. The option is cleared (/GR–) by default.
To find this option in the development environment, click Settings on the Project menu. Then click the C/C++ tab, and click C++ Language in the Category box.
解决方法:
project->Settings->c/c++(catagory)->c++ language
在Enable Runtime Type Information(RTTI)前勾选。
本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/miyunhong/archive/2010/01/15/5193589.aspx
相关文章推荐
- warning C4541: 'dynamic_cast' used on polymorphic type 'class CWnd' with /GR-; unpredictable behavio
- warning C4541: 'dynamic_cast' used on polymorphic type 'class CWnd' with /GR-; unpredictable behavior may result
- warning C4541: 'dynamic_cast' used on polymorphic type 'class CWnd' with /GR-; unpredictable behavi
- vc++ warning C4541 'typeid' used on polymorphic type with GR-
- warning C4541: “dynamic_cast”用在了带 /GR- 的多态类型“CWnd”上;可能导致不可预知的行为的解决办法
- Cannot call static method on type parameter, even with class constraint
- AFNetworking报错"_UTTypeCopyPreferredTagWithClass", referenced from: _AFContentTypeForPathExtens
- A TextureView or a subclass can only be used with hardware acceleration enabled.错误原因分析
- sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class异常解决方法
- Why the "volatile" type class should not be used
- 报org.apache.axis cannot be resolved to a type且Syntax error on token "enum", class expected错误
- 【MyEcplise】导入项目报错:Errors running builder 'JavaScript Validator' on project '项目名'. java.lang.ClassCastException
- sun.reflect.generics.reflectiveObjects.TypeVariableImpl cannot be cast to java.lang.Class
- Property 'date' not found on type java.lang.String] with root cause解决方案
- Replace Type Code with Class(以类取代型别码)
- chapter9: python 类的方法,属性,迭代器(new[old]-type class,[un]bound method,super,protocol,property,iterators)
- Playing with Content-Type – XXE on JSON Endpoints
- 重构手法30:Replace Type Code with Class (以类取代类型码)
- dynamic_cast < type-id > ( expression )
- ReplaceTypeCodeWithClass(以类取代类型码)