By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
446,260 Members | 1,243 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 446,260 IT Pros & Developers. It's quick & easy.

Casting away constness

P: n/a
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

Jul 19 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
On Mon, 17 Nov 2003 11:26:34 +0100, Martin Magnusson
<lo*******@frustratedhousewives.zzn.com> 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
Jul 19 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.