共用方式為


vector::const_reference

提供在 const 項目的參考型別在讀取及執行作業 const 向量中儲存。

typedef typename Allocator::const_reference const_reference;

備註

型別 const_reference 不能用來修改項目的值。

範例

// vector_const_ref.cpp
// compile with: /EHsc
#include <vector>
#include <iostream>

int main( )
{
   using namespace std;
   vector <int> v1;
   
   v1.push_back( 10 );
   v1.push_back( 20 );

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

需求

標題: <vector>

命名空間: std

請參閱

參考

vector Class

標準樣板程式庫