简体   繁体   English

G ++ 4.4编译错误,较低版本有效

[英]G++ 4.4 compile error, lower versions works

I have my program written in C++ and it is can be successfully compiled on Ubuntu 9.04 with g++ 4.3.4 and Solaris OS with g++ 3.4.3. 我的程序是用C ++编写的,它可以在Ubuntu 9.04上使用g ++ 4.3.4和Solaris OS with g ++ 3.4.3成功编译。 Now I have upgraded my Ubuntu to version 9.10 and g++ to version 4.4.1. 现在我已将Ubuntu升级到版本9.10,将g ++升级到版本4.4.1。 Now compiler invokes the error in STL. 现在编译器调用STL中的错误。

/usr/include/c++/4.4/bits/stl_deque.h: In member function ‘void std::deque<_Tp, _Alloc>::swap(std::deque<_Tp, _Alloc>&)’:
In file included from /usr/include/c++/4.4/deque:65,
/usr/include/c++/4.4/bits/stl_deque.h:1404: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1405: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1406: error: ‘swap’ is not a member of ‘std’
/usr/include/c++/4.4/bits/stl_deque.h:1407: error: ‘swap’ is not a member of ‘std’

I don't know how to fix it and if is possible that stl contains a bug. 我不知道如何解决它,如果可能stl包含一个bug。 Can you help me, please? 你能帮我吗?

Thanks a lot for all advices. 非常感谢所有的建议。

#include <algorithm>

In older versions of GCC, if you included any standard library header, that header would usually include many others. 在旧版本的GCC中,如果您包含任何标准库标头,则该标头通常会包含许多其他标头。 As mentioned by others, in your case <algorithm> got included this way. 正如其他人所提到的,在你的情况下, <algorithm>被包含在这种方式中。

This behavior isn't required by the standard. 标准不要求此行为。 Many other implementations of the standard library don't exhibit this behavior, or to a lesser degree. 标准库的许多其他实现不会表现出这种行为,或者程度较低。 It was just a design decision made by the GCC developers long ago. 这只是GCC开发人员很久以前做出的设计决定。 It seems they are now reducing this behavior, bringing it more in line with other implementations. 看起来他们现在正在减少这种行为,使其更符合其他实现。 This gives you more control over what gets included and what doesn't. 这使您可以更好地控制包含的内容和不包含的内容。 Old code will break, but it's easily fixed by including the missing headers. 旧代码会中断,但可以通过包含缺少的标头轻松修复。

Apple论坛上的帖子暗示

#include <algorithm>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM