VC.STL Newsgroup Good Questions(三)

来源:互联网 发布:ac控制器软件 编辑:程序博客网 时间:2024/04/27 12:24

VC.STL Newsgroup Good Questions()

         声明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::allocator >,class std::allocator,class std::allocator > > >' being compiled

 

代码如下:
#include

#include

using namespace std;

list myList;

void main()

{

}

 

再比如,map myMap

 

Answer:

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

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

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

一般建议你这么做:

#pragma warning(disable : 4786)

#include

#include

 

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

 

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

详情参见:

http://support.microsoft.com/support/kb/articles/Q167/3/55.ASP

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

 

(To be Continued)

 

Written by zhengyun@tomosoft.com

Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=12675