Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > issue with the stl and operators

Reply
Thread Tools

issue with the stl and operators

 
 
Sean Farrow
Guest
Posts: n/a
 
      08-31-2008
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: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.


 
Reply With Quote
 
 
 
 
Ian Collins
Guest
Posts: n/a
 
      08-31-2008
Paavo Helde wrote:
> "Sean Farrow" <> kirjutas:
>
>> 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: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)

>
> 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

--
Ian Collins.
 
Reply With Quote
 
 
 
 
Sean Farrow
Guest
Posts: n/a
 
      08-31-2008
Hi:
Thanks both, compiles successfully.
Sean.
"Ian Collins" <ian-> wrote in message
news:...
> Paavo Helde wrote:
>> "Sean Farrow" <> kirjutas:
>>
>>> 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: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)

>>
>> 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
>
> --
> Ian Collins.



 
Reply With Quote
 
Fraser Ross
Guest
Posts: n/a
 
      08-31-2008
"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.


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
stl and a class's list of overloadable operators? Rui Maciel C++ 1 03-02-2010 01:00 PM
a stl map which use stl pair as the key Allerdyce.John@gmail.com C++ 2 02-22-2006 07:25 AM
Copy elements from one STL container to another STL container Marko.Cain.23@gmail.com C++ 4 02-16-2006 05:03 PM
Where is the != >= > <= operators defined in STL? PengYu.UT@gmail.com C++ 1 10-22-2005 01:57 AM
To STL or not to STL Allan Bruce C++ 41 10-17-2003 08:21 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57