set::const_reference

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

typedef typename allocator_type::const_reference const_reference;

範例

// set_const_ref.cpp
// compile with: /EHsc
#include <set>
#include <iostream>

int main( )
{
   using namespace std;
   set <int> s1;

   s1.insert( 10 );
   s1.insert( 20 );

   // Declare and initialize a const_reference &Ref1 
   // to the 1st element
   const int &Ref1 = *s1.begin( );

   cout << "The first element in the set is "
        << Ref1 << "." << endl;

   // The following line would cause an error because the 
   // const_reference cannot be used to modify the set
   // Ref1 = Ref1 + 5;
}
  

需求

標題: <set>

命名空間: std

請參閱

參考

set Class

標準樣板程式庫