J
JustSomeGuy
When you iterate through a list of objects in a list.
list<object> mylist;
list<object>::const_iterator iter;
object ob;
for (iter=mylist.begin(); iter != mylist.end(); ++iter)
{
ob = *iter;
ob.value = 10;
}
So here I am iterating through the list
but is the statement ob = *iter making a copy of an element in my list?
or am I getting a refrence to an element in mylist?
It seems inefficient to me to make a copy of an element in the list, when
all I really want is a pointer to the object or a refrence to it so that
I can modify it...
I assume that iter->value is not going to work...
Comments?
list<object> mylist;
list<object>::const_iterator iter;
object ob;
for (iter=mylist.begin(); iter != mylist.end(); ++iter)
{
ob = *iter;
ob.value = 10;
}
So here I am iterating through the list
but is the statement ob = *iter making a copy of an element in my list?
or am I getting a refrence to an element in mylist?
It seems inefficient to me to make a copy of an element in the list, when
all I really want is a pointer to the object or a refrence to it so that
I can modify it...
I assume that iter->value is not going to work...
Comments?