Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   C++ (http://www.velocityreviews.com/forums/f39-c.html)
-   -   issue with the stl and operators (http://www.velocityreviews.com/forums/t633106-issue-with-the-stl-and-operators.html)

Sean Farrow 08-31-2008 07:24 AM

issue with the stl and operators
 
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::operator
()(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.



Ian Collins 08-31-2008 07:39 AM

Re: issue with the stl and operators
 
Paavo Helde wrote:
> "Sean Farrow" <sean.farrow@seanfarrow.co.uk> 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::operator ()(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.

Sean Farrow 08-31-2008 08:02 AM

Re: issue with the stl and operators
 
Hi:
Thanks both, compiles successfully.
Sean.
"Ian Collins" <ian-news@hotmail.com> wrote in message
news:6hv05qFnfi86U5@mid.individual.net...
> Paavo Helde wrote:
>> "Sean Farrow" <sean.farrow@seanfarrow.co.uk> 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::operator ()(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.




Fraser Ross 08-31-2008 10:06 AM

Re: issue with the stl and operators
 
"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.




All times are GMT. The time now is 10:06 AM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.