다음을 통해 공유


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 클래스

표준 템플릿 라이브러리