Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C++ > Casting away constness

Reply
Thread Tools

Casting away constness

 
 
Martin Magnusson
Guest
Posts: n/a
 
      11-17-2003
I have a typedef which looks like this:

typedef std::list< const S* const > seq_type;

I also have a class with a private field:

seq_type m_Sequence;

When calling the following method

M::AddSequence( seq_type seq )
{
m_Sequence.insert( m_Sequence.begin(),
seq.begin(),
seq.end() );
}

which is supposed to prepend the list "seq" to "m_Sequence" gcc tells me
that:

/usr/include/c++/3.2/bits/stl_construct.h:78: static_cast from type
`const S* const*' to type `void*' casts away constness

Why is that?

/ martin

 
Reply With Quote
 
 
 
 
tom_usenet
Guest
Posts: n/a
 
      11-17-2003
On Mon, 17 Nov 2003 11:26:34 +0100, Martin Magnusson
<(E-Mail Removed)> wrote:

>I have a typedef which looks like this:
>
>typedef std::list< const S* const > seq_type;


The above is illegal - the elements of a list must be assignable. So:

typedef std::list< const S* > seq_type;

would be allowed. Some implementations might allow the former, but it
isn't standard or portable.

>
>I also have a class with a private field:
>
>seq_type m_Sequence;
>
>When calling the following method
>
>M::AddSequence( seq_type seq )
>{
> m_Sequence.insert( m_Sequence.begin(),
> seq.begin(),
> seq.end() );
>}
>
>which is supposed to prepend the list "seq" to "m_Sequence" gcc tells me
>that:
>
>/usr/include/c++/3.2/bits/stl_construct.h:78: static_cast from type
>`const S* const*' to type `void*' casts away constness
>
>Why is that?


I suspect for the reason I listed above.

Tom
 
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
casting const away copx C Programming 58 02-10-2011 02:24 AM
casting away constness Laurent Deniau C Programming 3 09-12-2007 05:26 PM
Constness of the container of shared_ptr and the constness of it elements PengYu.UT@gmail.com C++ 14 04-04-2006 01:57 AM
Another question about inheritance (up-casting and down-casting) kevin Java 11 01-08-2005 07:11 PM
Casting Away Constness Trevor Lango C++ 15 01-02-2004 10:27 PM



Advertisments