issue with the stl and operators

S

Sean Farrow

Hi:
When compiling the folowing code under visual c++ 2005 I get he following
error:
C3848: expression having type 'const BitSetComp' would lose some
const-volatile qualifiers in order to call 'const bool BitSetComp::eek:perator
()(const KeyType &,const KeyType &)'
This is in the file xtree on line 1174. The code causing this is:
struct BitSetComp

{

bool const operator()(const KeyType& lhs, const KeyType& rhs)

{

return lhs.to_ulong() < rhs.to_ulong();

}

};

Anyone got a clue what the issue is, and what's causing this?

What is the solution?

Cheers

Sean.
 
I

Ian Collins

Paavo said:
Not enough info, but try:

bool operator() const (const KeyType& lhs, const KeyType& rhs)
Or if you want it to compile,

bool operator()(const KeyType& lhs, const KeyType& rhs) const
 
S

Sean Farrow

Hi:
Thanks both, compiles successfully.
Sean.
Ian Collins said:
Or if you want it to compile,

bool operator()(const KeyType& lhs, const KeyType& rhs) const
 
F

Fraser Ross

"Ian Collins"
Or if you want it to compile,

bool operator()(const KeyType& lhs, const KeyType& rhs) const


Is there any reason to make one non-constant? A functor wouldn't be
adaptable if it wasn't constant.


Fraser.
 

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,009
Latest member
GidgetGamb

Latest Threads

Top