|
-
January 12th, 2006, 04:46 PM
#1
How to convert from a const iterator to a non-const iterator? [Resolved]
Ok, here's the below snippet that's causing the problem.
Code:
bool graph::find_node(const std::string & node_name, const std::list<node * > & list)
{
for(std::list<graph::node * >::iterator iter = list.begin(); iter != list.end(); iter++)
{
if(( * ( * iter)).name == node_name)
{
return true;
}
}
return false;
}
Now the list that I'm using is a constant and I would like it to remain like that in order to prevent it from being changed in any way. However, it seems that the iterator that is created from it (in the boldened line) is also a const. How could I create a non-const iterator in this instance? Or convert the const iterator to a non-const one after creation?
[edit]
I could change the passed in list to a non-const and it'll work, but I would not like to break good programming practices in the process, which is the reason for the question.
Last edited by YourSurrogateGod; January 12th, 2006 at 04:48 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|