目录

queue::operator=

描述 (Description)

C ++函数std::queue::operator=通过替换旧的内容将新内容分配给队列,并在必要时修改大小。

声明 (Declaration)

以下是std :: queue :: operator = function form std :: queue header的声明。

C++11

queue<T, Container>& 
operator=( queue<T,Container>&& other );

参数 (Parameters)

other - 相同类型的另一个队列对象。

返回值

返回指针。

异常 (Exceptions)

该成员函数从不抛出异常。

时间复杂

线性即O(n)

例子 (Example)

以下示例显示了std :: queue :: operator = function的用法。

#include <iostream>
#include <queue>
#include <list>
using namespace std;
int main(void) {
   auto it1 = {1, 2, 3, 4, 5};
   auto it2 = {10, 20};
   queue<int> q1(it1);
   queue<int> q2(it2);
   q2 = move(q1);
   cout << "Contents of q1" << endl;
   while (!q1.empty()) {
      cout << q1.front() << endl;
      q1.pop();
   }
   cout << endl;
   cout << "Contents of q2" << endl;
   while (!q2.empty()) {
      cout << q2.front() << endl;
      q2.pop();
   }
   return 0;
}

让我们编译并运行上面的程序,这将产生以下结果 -

Contents of q1
Contents of q2
1
2
3
4
5
↑回到顶部↑
WIKI教程 @2018