简体   繁体   中英

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. Now I have upgraded my Ubuntu to version 9.10 and g++ to version 4.4.1. Now compiler invokes the error in 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. 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. As mentioned by others, in your case <algorithm> got included this way.

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. 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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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