繁体   English   中英

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

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

我的程序是用C ++编写的,它可以在Ubuntu 9.04上使用g ++ 4.3.4和Solaris OS with g ++ 3.4.3成功编译。 现在我已将Ubuntu升级到版本9.10,将g ++升级到版本4.4.1。 现在编译器调用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’

我不知道如何解决它,如果可能stl包含一个bug。 你能帮我吗?

非常感谢所有的建议。

#include <algorithm>

在旧版本的GCC中,如果您包含任何标准库标头,则该标头通常会包含许多其他标头。 正如其他人所提到的,在你的情况下, <algorithm>被包含在这种方式中。

标准不要求此行为。 标准库的许多其他实现不会表现出这种行为,或者程度较低。 这只是GCC开发人员很久以前做出的设计决定。 看起来他们现在正在减少这种行为,使其更符合其他实现。 这使您可以更好地控制包含的内容和不包含的内容。 旧代码会中断,但可以通过包含缺少的标头轻松修复。

Apple论坛上的帖子暗示

#include <algorithm>

暂无
暂无

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

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