系统管埋员
普通会员
发贴: 15
积分: 0
来自:
注册日期: 2007-10-17
发表时间: 2007-10-18 09:50:56
--------------------------------------------------------------------------------
解决VC中的有关STl 的4786编译警告
2007-05-20 22:03
--------------------Configuration: Cpp1 - Win32 Debug--------------------
Compiling...
Cpp1.cpp
D:\1prg\Microsoft Visual Studio\prg\menu\Cpp1.cpp(13) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; const *,std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::basi
c_string<char,std::char_traits<char>;,std::allocator<char>; >; const &,std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; const *,int>;' : identifier was truncated to '255' characters in the debug information
D:\1prg\Microsoft Visual Studio\prg\menu\Cpp1.cpp(13) : warning C4786: 'std::reverse_iterator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; *,std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::basic_stri
ng<char,std::char_traits<char>;,std::allocator<char>; >; &,std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; *,int>;' : identifier was truncated to '255' characters in the debug information
d:\1prg\microsoft visual studio\common\vc98\include\vector(47) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::allocator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; >; >;
::vector<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::allocator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; >; >;' : identifier was truncated to '255' characters in the debug information
d:\1prg\microsoft visual studio\common\vc98\include\vector(60) : warning C4786: 'std::vector<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::allocator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; >; >;
::~vector<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >;,std::allocator<std::basic_string<char,std::char_traits<char>;,std::allocator<char>; >; >; >;' : identifier was truncated to '255' characters in the debug information
Linking...
Cpp1.exe - 0 error(s), 4 warning(s)
在VC 6.0 上使用 STL 的时候会出现这种警告。是由于C++在内部生成的变量名超过了 255 个字符所致,在测试(Debug)版本中编译器限制生成的变量名的最大长度。一般可以忽略这类错误,想屏蔽它可以使用 #pragma warning (disable: 4786)。
你其实不用理会这个警告,因为它只会影响到Debugger,而不会影响到真实的代码。实际上,如果你编译一个Release版本的话,就会发现这个警告已经完全消失了。
消除这个警告可能有一点难度,因为这属于预处理器的行为。
一般建议你这么做:
#pragma warning(disable : 4786)
#include <string>
#include <vector>
注意这个pragma声明一定要放在stl头文件之前!否则不起作用!
这个pragma也不是总能够发生效力的!有时候,并不能消除所有的这种C4786警告。
详情参见:
http://support.microsoft.com/support/kb/articles/Q167/3/55.ASP
微软声称,将在Microsoft Visual C++ .NET中解决这个问题。
附该文:
BUG: You still receive a "warning C4768" message even if you use the warning pragma to disable the warning in Visual C++
View products that this article applies to.Article ID : 167355
Last Review : October 3, 2005
Revision : 3.0
This article was previously published under Q167355
On This Page
SYMPTOMS
STATUS
MORE INFORMATION
Sample code
SYMPTOMS
Warnings similar to the following are generated even if you use the warning pragma to disable the warning:
warning C4786:
'std::rb_tree<CAiSpanningTree<State,std::less<State>>::TransClosureNode, CAiSpanningTree<State,std::less<State>>::TransClosureNode,std::ident<Cai SpanningTree<State,std::less<State>>::TransClosureNode,CAiSpanningTree<S tate,std::less<State>>::TransClosureNode>,std::less<CAiSpanningTree<Stat e,std::less<State>>::TransClosureNode>>' : identifier was truncated to '255' characters in the debug information
The code:
#pragma warning(disable:4786)
disables warnings that list the file and line number. For example:
C:\test\Text.cpp(25) : warning C4786:
STATUS
Microsoft has confirmed that this is a bug in the Microsoft products that are listed in the "Applies to" section.
This problem was corrected in Microsoft Visual C++ .NET.
Back to the top
MORE INFORMATION
This warning can be ignored. However, the identifier may not be accessible or viewable in the debugger.
Sample code
/*
Compiler Options: /Zi
*/
#include <stddef.h>
#include <new.h>
#pragma warning(disable:4786)
namespace std {
template <class T, class U> struct ident {};
template <class T1, class T2> struct pair {};
template <class Arg1, class Arg2, class Result>
struct binary_function {};
template <class T>struct less : binary_function<T, T, bool> {};
template <class T, class Distance> struct bidirectional_iterator {};
template <class Key, class Value, class KeyOfValue, class Compare>
class rb_tree {
public:
typedef int size_type;
typedef int difference_type;
typedef void* link_type;
struct rb_tree_node {};
typedef Key key_type;
class iterator : public bidirectional_iterator<Value,
difference_type> {};
class const_iterator : public
bidirectional_iterator<Value,difference_type> {
protected:
link_type node;
const_iterator(link_type x) : node(x) {}
};
public:
size_type count(const key_type& x) const;
};
template <class Key, class Value, class KeyOfValue,
class Compare>
rb_tree<Key, Value, KeyOfValue, Compare>::size_type
rb_tree<Key, Value, KeyOfValue, Compare>::
count(const Key& k) const {
size_type n = 0;
return n;
};
template <class Key, class Compare> class set {
typedef ::std::rb_tree<Key, Key,ident<Key, Key>, Compare>
rep_type;
rep_type t;
};
}
template <class Node, class Compare>class CAiTransitiveClosure{
public:
typedef std::set<Node, Compare > NodeSet; NodeSet m_todo;
};
template <class Node, class Compare> class CAiSpanningTree {
public:
typedef std::set<Node, Compare > NodeSet;
protected:
typedef Node CAiSpanningTreeNode;
typedef NodeSet CAiSpanningTreeNodeSet;
private:
struct TransClosureNode {};
struct TransClosureGraph
: public CAiTransitiveClosure<TransClosureNode,
std::less<TransClosureNode> >
{};
public:
CAiSpanningTree(const Node& initialNode);
CAiSpanningTree(const NodeSet& initialNodes);
};
struct State { };
class CformSpanningTree:public CAiSpanningTree<State,std::less<State>>
{
public:
CFormSpanningTree( NodeSet initial)
: CAiSpanningTree<State, std::less<State> >(initial)
{}
};
坚持认为在“程序版”默认开启“显示表情图标”的设计者是太平盛世里最不和谐的音符。
此贴由系统管埋员在 2007-10-18 09:54 编辑过。
<---- 以上言论仅代表本人立场 ---->
系统管埋贡
普通会员
发贴: 2
积分: 0
来自:
注册日期: 2007-10-18
发表时间: 2007-10-18 16:02:19
--------------------------------------------------------------------------------
系统管埋员 提到:
...
坚持认为在“程序版”默认开启“显示表情图标”的设计者是太平盛世里最不和谐的音符。
...
使用 ASoundModem 可以将一切音符调制到和谐的区间内。 |
|