473,385 Members | 1,427 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

Casting away constness

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
1 2663
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

15
by: Trevor Lango | last post by:
I want to be able to cast away the constness of a private member variable in a member function of a class. I have the private data member declared as follows: const double x; I have an...
14
by: Enrico `Trippo' Porreca | last post by:
Given: typedef struct Node Node; struct Node { void *obj; Node *next; }; typedef struct Stack Stack; struct Stack {
31
by: dragoncoder | last post by:
Consider the code class A { private: int a; }; int main(void) { A x; int* ptr = (int*)&x;
7
by: dotnetchic | last post by:
Can someone explain to me the difference between static_cast<T>(v) and (what's the term for it?) old-style C cast? UINT value1 = 0; int value2 = (int)value1; int value2 =...
9
by: Alex Vinokur | last post by:
Is this approach safe? class Foo { // Stuff }; void func1 (void *) { // Do something
5
by: brekehan | last post by:
I've always been a little sketchy on the differences between static, dynamic, and reinterpret casting. I am looking to clean up the following block by using C++ casting instead of the C style...
2
by: Laurent Deniau | last post by:
I am looking for the "cleanest" way to cast away the constness of a pointee in C89, something like const_cast<T*>() in C++. Actually, I am using: #define CONST_CAST(typename,value) \ (((union {...
5
by: jason.cipriani | last post by:
There have been some recent threads about casting pointers to and from void* that have me rethinking some of my usual practices. I have a couple of questions. 1. What is the purpose of C++'s...
10
by: Alex Vinokur | last post by:
Hi, Is it possible to do C++-casting from const pair<const unsigned char*, size_t>* to const pair<unsigned char*, size_t>* ? Alex Vinokur
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.