fork download
  1. #include <vector>
  2. #include <iostream>
  3.  
  4. using std::cout;
  5. using std::endl;
  6. using std::vector;
  7.  
  8. void flipBool(bool & val)
  9. {
  10. val = !val;
  11. }
  12.  
  13. int main()
  14. {
  15. std::vector<bool> vec{true, false, true, false, true};
  16.  
  17. for (auto & val : vec) { // Сасай-кудасай для vector<bool>, ОК для остальных
  18. cout << val << endl;
  19. }
  20.  
  21. bool *firstValPointer = &vec[0]; // Сасай-кудасай для vector<bool>, ОК для остальных
  22.  
  23. flipBool(vec[0]); // Сасай-кудасай.
  24.  
  25. return EXIT_SUCCESS;
  26. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp:17:14: error: non-const lvalue reference to type 'std::_Bit_reference' cannot bind to a temporary of type 'reference' (aka 'std::_Bit_reference')
        for (auto & val : vec) {  // Сасай-кудасай для vector<bool>, ОК для остальных
                    ^   ~
/usr/bin/../lib/gcc/x86_64-linux-gnu/6.3.0/../../../../include/c++/6.3.0/bits/stl_bvector.h:779:5: note: selected 'begin' function with iterator type 'iterator' (aka 'std::_Bit_iterator')
    begin() _GLIBCXX_NOEXCEPT
    ^
prog.cpp:21:26: error: taking the address of a temporary object of type 'reference' (aka 'std::_Bit_reference') [-Waddress-of-temporary]
        bool *firstValPointer = &vec[0];  // Сасай-кудасай для vector<bool>, ОК для остальных
                                ^~~~~~~
prog.cpp:21:8: error: cannot initialize a variable of type 'bool *' with an rvalue of type 'reference *' (aka 'std::_Bit_reference *')
        bool *firstValPointer = &vec[0];  // Сасай-кудасай для vector<bool>, ОК для остальных
              ^                 ~~~~~~~
prog.cpp:23:2: error: no matching function for call to 'flipBool'
        flipBool(vec[0]);  // Сасай-кудасай.
        ^~~~~~~~
prog.cpp:8:6: note: candidate function not viable: no known conversion from 'reference' (aka 'std::_Bit_reference') to 'bool &' for 1st argument
void flipBool(bool & val)
     ^
4 errors generated.
stdout
Standard output is empty