我error: ‘class std::queue<int>’ has no member named ‘swap’
在编译以下代码时
#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;
}
我正在使用g++ (Ubuntu/Linaro 4.6.3-1ubuntu5) 4.6.3
此代码进行编译,有人可以对此错误有一个想法吗?
使用:
std::swap(foo, bar);
从c ++ 11开始,您似乎有了std :: queue :: swap
http://www.cplusplus.com/reference/queue/queue/swap-free/
g ++ 4.6似乎不接受-std = c ++ 11,因此您必须升级编译器才能使此方法起作用。
[编辑]
g ++ 4.6接受-std = c ++ 0x以启用c ++ 11
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句