次の方法で共有


queue::queue

空か、基本コンテナー オブジェクトのコピーであるキューを構築します。

queue( ); 
explicit queue(
   const container_type& _Right
);

パラメーター

  • _Right
    構築されたキューがコピーであることです [const] のコンテナー。

解説

キューの既定のベース コンテナーは、deque です。必要な pop_front のメンバー関数がないため、ベースのコンテナーとしてリストを指定できますが、ベクターを指定できません。

使用例

// queue_queue.cpp
// compile with: /EHsc
#include <queue>
#include <vector>
#include <list>
#include <iostream>

int main( )
{
   using namespace std;

   // Declares queue with default deque base container
   queue <char> q1;

   // Explicitly declares a queue with deque base container
   queue <char, deque<char> > q2;

   // These lines don't cause an error, even though they
   // declares a queue with a vector base container
   queue <int, vector<int> > q3;
   q3.push( 10 );
   // but the following would cause an error because vector has 
   // no pop_front member function
   // q3.pop( );

   // Declares a queue with list base container
   queue <int, list<int> > q4;
   
   // The second member function copies elements from a container
   list<int> li1;
   li1.push_back( 1 );
   li1.push_back( 2 );
   queue <int, list<int> > q5( li1 );
   cout << "The element at the front of queue q5 is "
        << q5.front( ) << "." << endl;
   cout << "The element at the back of queue q5 is "
        << q5.back( ) << "." << endl;
}
  
  

必要条件

ヘッダー: <queue>

名前空間: std

参照

関連項目

queue Class

標準テンプレート ライブラリ