向量<bool>::reference::operator=

将布尔值到由或引用的元素代表的值赋给位。

reference& operator=(
   const reference& _Right
);
reference& operator=(
   bool _Val
);

参数

  • _Right
    元素引用其值将分配给位。

  • _Val
    将分配的布尔值到由。

返回值

指定或引用的布尔值。

示例

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

class MyAlloc{};
int main( ) 
{
   using namespace std;

   typedef vector<bool> boolvector;
   boolvector v;
   bool b1, b2;

   v.push_back( false );
   v.push_back( true );
   boolvector::reference ref1 = v.at( 0 );
   boolvector::reference ref2 = v.at( 1 );
   b1 = ref1;
   b2 = ref2;
   cout << "The initial value of the 1st element was: " << b1 << endl;
   cout << "The initial value of the 2nd element was: " << b2 << endl;

   ref2.operator=( ref1 );
   b2 = ref2;
   cout << "The value of the 2nd element is now: " << b2 << endl;

   ref1.operator=( true );
   b1 = bool( ref1 );
   cout << "The value of the 1st element is now: " << b1 << endl;
}
  

要求

标头: <vector>

命名空间: std

请参见

参考

vector<bool>::reference Class

标准模板库