warning C4786 详解(VC++6.0)

来源:互联网 发布:数据库sql注入攻击 编辑:程序博客网 时间:2024/05/16 14:48

程序中在使用list的时候,如 std::list(#include <list>),std::vector,map的时候,有时候会出现下列类似Warning;

我的程序使用的是std::list:

 

1 Warning:

d:/program files/microsoft visual studio/vc98/include/list(176) : warning C4786: '?rbegin@?$list@PAUMODULE_DESC_V2300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@QAE?AV?$reverse_bidirectional_iterator@Viterator@?$list@PAUMODULE_DESC_V2300t
ag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@PAUMODULE_DESC_V2300tag@@AAPAU4@PAPAU4@H@2@XZ' : identifier was truncated to '255' characters in the browser information
        E:/XX.cpp(81) : see reference to class template instantiation 'std::list<struct MODULE_DESC_V2300tag *,class std::allocator<struct MODULE_DESC_V2300tag *> >' being compiled
d:/program files/microsoft visual studio/vc98/include/list(178) : warning C4786: '?rbegin@?$list@PAUMODULE_DESC_V2300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@QBE?AV?$reverse_bidirectional_iterator@Vconst_iterator@?$list@PAUMODULE_DESC_
V2300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@PAUMODULE_DESC_V2300tag@@ABQAU4@PBQAU4@H@2@XZ' : identifier was truncated to '255' characters in the browser information
        E:/XX.cpp(81) : see reference to class template instantiation 'std::list<struct MODULE_DESC_V2300tag *,class std::allocator<struct MODULE_DESC_V2300tag *> >' being compiled
d:/program files/microsoft visual studio/vc98/include/list(180) : warning C4786: '?rend@?$list@PAUMODULE_DESC_V2300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@QAE?AV?$reverse_bidirectional_iterator@Viterator@?$list@PAUMODULE_DESC_V2300tag
@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@PAUMODULE_DESC_V2300tag@@AAPAU4@PAPAU4@H@2@XZ' : identifier was truncated to '255' characters in the browser information
        E:/XX.cpp(81) : see reference to class template instantiation 'std::list<struct MODULE_DESC_V2300tag *,class std::allocator<struct MODULE_DESC_V2300tag *> >' being compiled
d:/program files/microsoft visual studio/vc98/include/list(181) : warning C4786: '?rend@?$list@PAUMODULE_DESC_V2300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@QBE?AV?$reverse_bidirectional_iterator@Vconst_iterator@?$list@PAUMODULE_DESC_V2
300tag@@V?$allocator@PAUMODULE_DESC_V2300tag@@@std@@@std@@PAUMODULE_DESC_V2300tag@@ABQAU4@PBQAU4@H@2@XZ' : identifier was truncated to '255' characters in the browser information
        E:/XX.cpp(81) : see reference to class template instantiation 'std::list<struct MODULE_DESC_V2300tag *,class std::allocator<struct MODULE_DESC_V2300tag *> >' being compiled

 

2 原因:

此warning产生的原因是因为标识符过长,超过了最大限定255个字。类名超过了255个字,使用时就会报4786的waring。在使用STL(C++标准模板库)的时候经常引发类似的错误,尤其是list,vector,map这类模板类,模板中套模板,一不小心就超长了。

 

3 解决方法:

 

3.1直接定义别名:
#ifdef _DEBUG
#define TooLongClassNameA A
#define TooLongClassNameB B
#endif

3.2 屏蔽4786warning:
#pragma warning(disable : 4786)
 
屏蔽语句必须放在报错的模板类的引用声明(如#include <list>)之前,否则还是不起作用。