Re: const question [C++]
From: BobR (RemoveBadBobR_at_worldnet.att.net)
Date: 03/23/05
- Next message: David White: "Re: const question"
- Previous message: Mark P: "Re: const question"
- In reply to: Mark P: "Re: const question"
- Next in thread: Anthony Borla: "Re: const question [C++]"
- Reply: Anthony Borla: "Re: const question [C++]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Tue, 22 Mar 2005 23:08:01 GMT
Mark P wrote in message ...
>Alf P. Steinbach wrote:
>>
>> I'd advice against that. Mark's description of the case means that
>> const iterator is correct, and making the set mutable would probably be
worse
>> than simply removing 'const' everywhere. The problems lie, as Mark
writes,
>> "elsewhere", and without any description of that no advice can be given.
>
>Fair enough, here's the gist of it. My const function is to return a
>pair of iterators representing a range in the set. This range is
>processed in a variety of ways, none of which affect the underlying set,
>and then eventually I want to erase the elements in the range from the
>set. There the const iterator becomes problematic.
>
>The problem as I understand it is that a const function won't let me
>return a non-const iterator (or a pair of the same) even though the
>function never attempts to modify the set via the iterator.
>
>So what's the recommended style to handle this? I could just eradicate
>the const declarations everywhere a conflict arises, but that's rather
>drastic. Is there a way to cast away the const'ness of an iterator?
const_cast<type>(const_something);
"Hey, you compiler! I'll take control of this one. Thanks for your help,
but, I know what I'm doing. I know it's 'const', you know it's 'const', it's
that stupid variable. It wants a non-const type, so, I need to fool it!!
Don't worry, I'll be sure not to do something stupid with it." <G>
Is that close to what you are looking for?
-- Bob R POVrookie -- MinGW (GNU compiler): http://www.mingw.org/ Dev-C++ IDE: http://www.bloodshed.net/ POVray: http://www.povray.org/ alt.comp.lang.learn.c-c++ faq: http://www.comeaucomputing.com/learn/faq/
- Next message: David White: "Re: const question"
- Previous message: Mark P: "Re: const question"
- In reply to: Mark P: "Re: const question"
- Next in thread: Anthony Borla: "Re: const question [C++]"
- Reply: Anthony Borla: "Re: const question [C++]"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|