deque::const_reference
提供对 const 元素的类型在读取和执行的 const 操作过程、向量、双端队列存储状态。
typedef typename Allocator::const_reference const_reference;
备注
类型 const_reference 不能用于修改元素的值。
示例
// deque_const_ref.cpp
// compile with: /EHsc
#include <deque>
#include <iostream>
int main( )
{
using namespace std;
deque <int> c1;
c1.push_back( 10 );
c1.push_back( 20 );
const deque <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 as c2 is const
// c2.push_back( 30 );
}
要求
标头: <deque>
命名空间: std