pointer

how do i reference a global list using a pointer? i'm doing the following, with global->m_var1 and global->m_var2 being the global lists;

1
2
3
4
5
6
list<int> myLocalList;

if(some_var == 1)
&myLocalList = global->m_var1;
else
&myLocalList = global->m_var2;


and the above giving me errors, where am i going wrong?
You can't assign a global list pointer to a local instance. Are you trying to copy the global to local? Are you just wanting a local access pointer to a global list? Tell us what you are trying to accomplish with the above code.

You can't assign something to the address of a variable. The following code:
&myVariable = whatever;
basically means "Move myVariable to the 'whatever' memory slot".

Also, 'global->' means nothing unless 'global' is a pointer to an object (which would be very oddly named, mind you).

We can't really help you without more information on what you're trying to accomplish.
if i wasnt clear in my first post i apologize, heres is what i want to do - i want the locallist to pointer the globallist, ill be updating the locallist either by erasing or inserting into the list where i also want the global list to be modified when the locallist is
Then just make your local list a pointer?
1
2
3
4
list<int> * pLocalList;
//...
pLocalList = &global;
//... 
Last edited on
i've tried this and errors
"left of '.begin' must have class/struct/union type"

1
2
3
4
5
6
list<int> *myLocalList = &global->m_var2;

if(some_var == 1)
myLocalList = &global->m_var1;

list<int>::iterator Iter1 = myLocalList.begin(), Iter2 = myLocalList.end();
Last edited on
still, having this problem, no one knows whats wrong?
You need to use myLocalList->begin() because it's a pointer.
Topic archived. No new replies allowed.