fork download
  1. #include <vector>
  2. #include <algorithm>
  3.  
  4. struct MyClass
  5. {
  6. int a;
  7. int b;
  8. bool operator < (const MyClass& other){return other.a < a;}
  9. };
  10.  
  11. typedef std::vector<MyClass> MyVector;
  12.  
  13. int main()
  14. {
  15. MyVector test;
  16. const MyVector& stupidError = test;
  17. std::sort(stupidError.begin(), stupidError.end());
  18. return 0;
  19. }
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
In file included from /usr/include/c++/4.8/algorithm:62:0,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘void std::__insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’:
/usr/include/c++/4.8/bits/stl_algo.h:2235:62:   required from ‘void std::__final_insertion_sort(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:5476:47:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
prog.cpp:17:50:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:2161:13: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    if (*__i < *__first)
             ^
/usr/include/c++/4.8/bits/stl_algo.h:2166:17: error: passing ‘const MyClass’ as ‘this’ argument of ‘MyClass& MyClass::operator=(MyClass&&)’ discards qualifiers [-fpermissive]
        *__first = _GLIBCXX_MOVE(__val);
                 ^
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’:
/usr/include/c++/4.8/bits/stl_algo.h:5322:51:   required from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:2333:60:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Size = int]’
/usr/include/c++/4.8/bits/stl_algo.h:5475:36:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
prog.cpp:17:50:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:1959:11: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
  if (*__i < *__first)
           ^
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘void std::__move_median_first(_Iterator, _Iterator, _Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’:
/usr/include/c++/4.8/bits/stl_algo.h:2306:60:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:2338:54:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Size = int]’
/usr/include/c++/4.8/bits/stl_algo.h:5475:36:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
prog.cpp:17:50:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:84:16: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
       if (*__a < *__b)
                ^
/usr/include/c++/4.8/bits/stl_algo.h:86:13: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    if (*__b < *__c)
             ^
/usr/include/c++/4.8/bits/stl_algo.h:88:18: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    else if (*__a < *__c)
                  ^
/usr/include/c++/4.8/bits/stl_algo.h:91:21: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
       else if (*__a < *__c)
                     ^
/usr/include/c++/4.8/bits/stl_algo.h:93:21: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
       else if (*__b < *__c)
                     ^
/usr/include/c++/4.8/bits/stl_algo.h: In instantiation of ‘_RandomAccessIterator std::__unguarded_partition(_RandomAccessIterator, _RandomAccessIterator, const _Tp&) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Tp = MyClass]’:
/usr/include/c++/4.8/bits/stl_algo.h:2307:70:   required from ‘_RandomAccessIterator std::__unguarded_partition_pivot(_RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:2338:54:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Size = int]’
/usr/include/c++/4.8/bits/stl_algo.h:5475:36:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
prog.cpp:17:50:   required from here
/usr/include/c++/4.8/bits/stl_algo.h:2266:20: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    while (*__first < __pivot)
                    ^
/usr/include/c++/4.8/bits/stl_algo.h:2269:19: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    while (__pivot < *__last)
                   ^
In file included from /usr/include/c++/4.8/bits/stl_algo.h:61:0,
                 from /usr/include/c++/4.8/algorithm:62,
                 from prog.cpp:2:
/usr/include/c++/4.8/bits/stl_heap.h: In instantiation of ‘void std::__adjust_heap(_RandomAccessIterator, _Distance, _Distance, _Tp) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Distance = int; _Tp = MyClass]’:
/usr/include/c++/4.8/bits/stl_heap.h:407:71:   required from ‘void std::make_heap(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:1957:39:   required from ‘void std::__heap_select(_RandomAccessIterator, _RandomAccessIterator, _RandomAccessIterator) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:5322:51:   required from ‘void std::partial_sort(_RAIter, _RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
/usr/include/c++/4.8/bits/stl_algo.h:2333:60:   required from ‘void std::__introsort_loop(_RandomAccessIterator, _RandomAccessIterator, _Size) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >; _Size = int]’
/usr/include/c++/4.8/bits/stl_algo.h:5475:36:   required from ‘void std::sort(_RAIter, _RAIter) [with _RAIter = __gnu_cxx::__normal_iterator<const MyClass*, std::vector<MyClass> >]’
prog.cpp:17:50:   required from here
/usr/include/c++/4.8/bits/stl_heap.h:235:35: error: passing ‘const MyClass’ as ‘this’ argument of ‘bool MyClass::operator<(const MyClass&)’ discards qualifiers [-fpermissive]
    if (*(__first + __secondChild) < *(__first + (__secondChild - 1)))
                                   ^
/usr/include/c++/4.8/bits/stl_heap.h:237:29: error: passing ‘const MyClass’ as ‘this’ argument of ‘MyClass& MyClass::operator=(const MyClass&)’ discards qualifiers [-fpermissive]
    *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first + __secondChild));
                             ^
/usr/include/c++/4.8/bits/stl_heap.h:243:29: error: passing ‘const MyClass’ as ‘this’ argument of ‘MyClass& MyClass::operator=(const MyClass&)’ discards qualifiers [-fpermissive]
    *(__first + __holeIndex) = _GLIBCXX_MOVE(*(__first
                             ^
stdout
Standard output is empty