fork download
  1. #include <vector>
  2.  
  3. struct foo {
  4. std::vector<int> p;
  5. };
  6.  
  7. void someFunction(const foo& theFoo)
  8. {
  9. theFoo.p[0] = 10; // error.
  10. }
  11.  
  12. int main()
  13. {
  14. foo aFoo;
  15. aFoo.p.resize(1);
  16. someFunction(aFoo);
  17. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
prog.cpp: In function 'void someFunction(const foo&)':
prog.cpp:9:18: error: assignment of read-only location 'theFoo.foo::p.std::vector<_Tp, _Alloc>::operator[]<int, std::allocator<int> >(0u)'
      theFoo.p[0] = 10;  // error.
                  ^
stdout
Standard output is empty