Share via


list::const_reference

読み取りと const 操作の実行のために、リストに格納された const 要素への参照を提供する型。

typedef typename Allocator::const_reference const_reference;

解説

const_reference 型で要素の値を変更することはできません。

使用例

// list_const_ref.cpp
// compile with: /EHsc
#include <list>
#include <iostream>

int main( ) 
{
   using namespace std;
   list <int> c1;
   
   c1.push_back( 10 );
   c1.push_back( 20 );

   const list <int> c2 = c1;
   const int &i = c2.front( );
   const int &j = c2.back( );
   cout << "The first element is " << i << endl;
   cout << "The second element is " << j << endl;
   
   // The following line would cause an error because c2 is const
   // c2.push_back( 30 );
}
  

必要条件

ヘッダー: <list>

名前空間: std

参照

関連項目

list クラス

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