473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Problem with iterators and conts

Hello,

I've got the following code:

//Begin foo.cpp
#include <set>
#include <vector>

class sq_t
{
int m_priority;
public:
void ClearPriority() { m_priority = 0; }
};

typedef std::set<sq_t> its_t;
typedef std::vector<sq_t> sq_seq_t;

class TDM_t
{
public:
typedef std::set<sq_t> its_t;
its_t m_IT;
};

int main( )
{
TDM_t tdm;

for (its_t::iterator i_it = tdm.m_IT.begin();
i_it != tdm.m_IT.end(); ++i_it )
{
(*i_it).ClearPriority(); //this is line 29
}
}
//End foo.cpp

The compiler (g++ 3.2.3) complains:

foo.cpp: In function `int main()':
foo.cpp:29: passing `const sq_priority_t' as `this' argument of `void
sq_priority_t::ClearPriority()' discards qualifiers

I think that I understand the problem which is related to this line:

typedef typename _Rep_type::const_iterator iterator;

in stl_set.h

I'm pretty sure I need to use const_cast to solve the problem but I
can't seem to get the syntax right. Help!

-exits

Jul 22 '05 #1
1 1107
"Exits Funnel" <ex***************@yahoo.com> wrote...
[...] Help!


Changing a set element may screw up the relative order of things in
the set without letting the set know so it could reorder them. It
is generally unsafe to change values in the set through the set's
iterators, that's why in some implementations it's a const_iterator.
The right way would be to remove the old element and insert another
one.

V
Jul 22 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

45
2979
by: Joh | last post by:
hello, i'm trying to understand how i could build following consecutive sets from a root one using generator : l = would like to produce : , , , ,
8
1981
by: babak | last post by:
Hi everyone I have a problem with Iterators and containers in STL that hopefully someone can help me with. This is what I try to do: I have an associative (map) container and I have a...
15
2157
by: fungus | last post by:
I'm moving some code from VC++ 6 to VC++ 2005 and I've run into a nasty problem because iterators are no longer pointers. In the program I'm moving, there's a std::vector of items hidden inside...
18
2092
by: desktop | last post by:
1) I have this code: std::list<intmylist; mylist.push_back(1); mylist.push_back(2); mylist.push_back(3); mylist.push_back(4);
0
7271
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7319
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6979
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5570
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4998
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 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 a new...
0
3160
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.