Discard qualifiers

J

john

Hi,
I'm trying to sort a vector using
sort(corelist.begin(),corelist.end());
so I've provided a method to overload the < operator in the file, like
so, but it isn't a class member and the code which uses it is in
another file containing a class which inherits from this class:

bool operator< ( const Core& a, const Core& b) {
return a.getdistance() < b.getdistance();

}

Only problem is I get a const discard qualifiers error, which seems
very annoying. It seems to make me choose whether I want to hide my
code's variables or have them const. Removing the const seems to allow
the program to compile but there are a lot of errors (top line of
which shown below). getdistance just returns a double and I'm using
gcc. I haven't got a == operator in the code, but think I may possibly
need one.

Any help would be gratefully received

/usr/lib/gcc/i686-pc-linux-gnu/4.1.2/include/g++-v4/bits/stl_algo.h:
In function 'void std::partial_sort(_RandomAccessIterator,
_RandomAccessIterator, _RandomAccessIterator) [with
_RandomAccessIterator = __gnu_cxx::__normal_iterator<Core*,
std::vector<Core, std::allocator<Core> > >]':
 
B

Ben Pfaff

john said:
I'm trying to sort a vector using
sort(corelist.begin(),corelist.end());
so I've provided a method to overload the < operator in the file, like
so, but it isn't a class member and the code which uses it is in
another file containing a class which inherits from this class:

You are likely to get better responses to C++ questions in
comp.lang.c++.
 
S

Seebs

bool operator< ( const Core& a, const Core& b) {

You might want comp.lang.c++.

Alternatively, I could just point out that this is a syntax error and
won't compile, and that's probably your problem.

Your call. :)

-s
 
P

Phil Carmody

Ben Pfaff said:
I'm not going to spend more time searching for a reason to call
an article a troll than I would spend writing up a completely
reasonable answer to it.

So what? I did not suggest that you spend any time *searching* for
a reason to *call* an article a troll. I suggested that you evolve
an ability to detect such completely obvious trolls without needing
to perform a search, and that once you've so detected them, there's
no need for any response at all.

Phil
 
B

Ben Pfaff

Phil Carmody said:
So what? I did not suggest that you spend any time *searching* for
a reason to *call* an article a troll. I suggested that you evolve
an ability to detect such completely obvious trolls without needing
to perform a search, and that once you've so detected them, there's
no need for any response at all.

I don't know how you tell the difference between an article
carelessly posted to the wrong newsgroup and a troll. To me, the
article resembled the former more than the latter.
 
N

Nick Keighley

So what? I did not suggest that you spend any time *searching* for
a reason to *call* an article a troll. I suggested that you evolve
an ability to detect such completely obvious trolls without needing
to perform a search,
how?

and that once you've so detected them, there's
no need for any response at all.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,007
Latest member
obedient dusk

Latest Threads

Top