[Bug libstdc++/32851] Sort of vector of template class fails
pinskia at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Mon Jul 23 21:55:00 GMT 2007
------- Comment #2 from pinskia at gcc dot gnu dot org 2007-07-23 21:55 -------
The error message is:
/home/apinski/x86-local-fsf/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algo.h:2789:
instantiated from 'void std::sort(_RandomAccessIterator,
_RandomAccessIterator) [with _RandomAccessIterator =
__gnu_cxx::__normal_iterator<card*, std::vector<card, std::allocator<card> >
>]'
t1212.cc:17: instantiated from 'void cards<MyCard>::sort() [with MyCard =
card]'
t1212.cc:25: instantiated from here
/home/apinski/x86-local-fsf/lib/gcc/i686-pc-linux-gnu/4.3.0/../../../../include/c++/4.3.0/bits/stl_algo.h:92:
error: passing 'const card' as 'this' argument of 'bool card::operator<(const
card&)' discards qualifiers
This is correct, you need to mark operator< as taking a const this variable.
Like:
bool operator<(const card & A)const { return this->id < A.id;};
Once doing that, the program compiles.
--
pinskia at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Component|c++ |libstdc++
Resolution| |INVALID
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=32851
More information about the Gcc-bugs
mailing list