现在的位置: 首页 > 综合 > 正文

VC6.0中C4541号警告的原因以及解决方案

2014年02月04日 ⁄ 综合 ⁄ 共 1123字 ⁄ 字号 评论关闭
1.
VC6.0中C4541号警告的原因以及解决方案
2007-09-05 15:04

今天在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 theCategory box.

在VC6.0的Project->Setting->c/c++的Project Options 中 增加/GR,然后编译,发现出现一个新的警告C4652,解决办法如下:

2.警告C4652如何解除

原文:http://topic.csdn.net/t/20021015/18/1099387.html

REBUILD   ALL

在VC6.0中Build->Rebuild ALL,OK,问题解决。

warning C4652 编译错误如何解除?


warning C4652 编译错误如何解除?


warning C4652 编译错误如何解除?

抱歉!评论已关闭.