Udostępnij za pośrednictwem


vector<bool>::reference::operator=

Assigns a Boolean value to a bit or the value held by a referenced element to a bit.

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

Parameters

  • _Right
    The element reference whose value is to be assigned to the bit.

  • _Val
    The Boolean value to be assigned to the bit.

Return Value

The Boolean value either designated or referred to.

Example

// 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;
}
The initial value of the 1st element was: 0
The initial value of the 2nd element was: 1
The value of the 2nd element is now: 0
The value of the 1st element is now: 1

Requirements

Header: <vector>

Namespace: std

See Also

Reference

vector<bool>::reference Class

Standard Template Library

Other Resources

vector<bool>::reference Members