posts - 274,  comments - 1258,  trackbacks - 0

声明 Container 对象时有许多 C 4786 编译警告, Why?

Article last modified on 2002-5-29

----------------------------------------------------------------

The information in this article applies to:

-         Microsoft Visual C++, 32-bit Editions, version 6.0, SP5

----------------------------------------------------------------

 

Question:

下面的代码编译时报告了一大堆愚蠢的 C4786 编译警告,足有十四个:

f:\program files\microsoft visual studio\vc98\include\list(125) : warning C4786: '?$reverse_bidirectional_iterator@Viterator@?$list@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@V?$allocator@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@std@@@2@@std@@V?$basic_string@DU?$char_traits@D@std@@V?$allocator@D@2@@3@AAV43@PAV43@H' : identifier was truncated to '255' characters in the browser information        E:\ \Exercise4\Exercise4.cpp(195) : see reference to class template instantiation 'std::list<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> >,class std::allocator<class std::basic_string<char,struct std::char_traits<char>,class std::allocator<char> > > >' being compiled

 

代码如下:
#include <list>

#include <string>

using namespace std;

list<string> myList;

void main()

{

}

 

再比如, map<string,int> myMap

 

Answer:

这个警告的意思就是说, list<string> 的构造生成的 Symbols 太长了,超过了255个字符。

你其实不用理会这个警告,因为它只会影响到 Debugger ,而不会影响到真实的代码。实际上,如果你编译一个 Release 版本的话,就会发现这个警告已经完全消失了。

消除这个警告可能有一点难度,因为这属于预处理器的行为。

一般建议你这么做:

#pragma warning(disable : 4786)

#include <list>

#include <string>

 

注意这个 pragma 声明一定要放在 stl 头文件之前!否则不起作用!

 

这个 pragma 也不是总能够发生效力的!有时候,并不能消除所有的这种 C4786 警告。

详情参见:

																						
																								ASP" target=_top>http://support.microsoft.com/support/kb/articles/Q167/3/55.ASP
																				

微软声称,将在 Microsoft Visual C++ .NET 中解决这个问题。

 

(To be Continued)

 

Written by zhengyun@tomosoft.com

 

---
本文章使用开源内容管理kicoy发布

oy.com">开源内容管理kicoy发布

posted on 2006-06-12 11:41 踏雪赤兔 阅读(3199) 评论(0)  编辑 收藏 引用 所属分类: 玩转编程
只有注册用户登录后才能发表评论。

百度空间| 见闻日记| 编程感悟
我的twitter


LOGO

自我介绍:百度厂基础平台车间的一名挨踢民工。擅长C++、算法、语言设计、分布式计算,也用过Java,Python, PHP,JS/AS等语言开发。请关注我的twitter (免翻墙版) 发QQ消息


添加到收藏夹 Locations of visitors to this page

常用链接

随笔分类(300)

随笔档案(274)

文章分类(38)

相册

收藏夹(54)

与博主互动

博客手拉手

搜索

  •  

积分与排名

  • 积分 - 392920
  • 排名 - 10

最新评论

阅读排行榜

评论排行榜