Reputation: 5816
I have error: ‘class std::queue<int>’ has no member named ‘swap’
while compiling following code
#include <iostream> // std::cout
#include <queue> // std::queue
int main ()
{
std::queue<int> foo,bar;
foo.push (10); foo.push(20); foo.push(30);
bar.push (111); bar.push(222);
foo.swap(bar);
std::cout << "size of foo: " << foo.size() << '\n';
std::cout << "size of bar: " << bar.size() << '\n';
return 0;
}
I'm using g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
for compiling this code,can anyone have a idea for this error?
Upvotes: 1
Views: 2629
Reputation: 50026
Use:
std::swap(foo, bar);
It appear that since c++11, you have std::queue::swap
http://www.cplusplus.com/reference/queue/queue/swap-free/
g++ 4.6 appears to not accept -std=c++11, so you must upgrade your compiler for this method to work.
[edit]
g++ 4.6 accepts -std=c++0x to enable c++11
Upvotes: 5