Casting away constness

M

Martin Magnusson

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
 
T

tom_usenet

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
 

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,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top