fork download
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. vector<bool> vec({false, false, true, false});
  7.  
  8. bool &some_bool = vec[2];
  9. some_bool = false;
  10. cout << vec[2] << '\n';
  11. return 0;
  12. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function ‘int main()’:
prog.cpp:8:25: error: invalid initialization of non-const reference of type ‘bool&’ from an rvalue of type ‘bool’
  bool &some_bool = vec[2];
                    ~~~~~^
In file included from /usr/include/c++/6/vector:65:0,
                 from prog.cpp:2:
/usr/include/c++/6/bits/stl_bvector.h:80:5: note:   after user-defined conversion: std::_Bit_reference::operator bool() const
     operator bool() const _GLIBCXX_NOEXCEPT
     ^~~~~~~~
stdout
Standard output is empty