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