When i put a pointer in a container(std::list) and then retrieve it from another object the pointe is the same but i cant access the object.
example
std::list<myobject*> list
list.push_back(pobject1)//myobject*opbject1
in visual studio says pointer is 0x12345678
from another object i get the list
myobject*pobject2 = list.back() //to get the pointer
the pointer is 0x12345678, same as above
when i do pobject2->something() throws errors, and if i put a breakpoint and check the pointer the values are all COMPLETELY MESSED UP
it gives me a HUGE problem in my application and i hope someone will help
pointers and containers
-
- Kobold
- Posts: 26
- Joined: Thu Jan 26, 2012 8:36 pm
pointers and containers
Last edited by vblanco on Fri Mar 09, 2012 10:16 pm, edited 2 times in total.
-
- Greenskin
- Posts: 146
- Joined: Mon Jan 10, 2011 7:39 pm
- x 9
Re: pointers and containers
Use
Code: Select all
myobject*pobject2 = list.back(); //to get the pointer
-
- Kobold
- Posts: 26
- Joined: Thu Jan 26, 2012 8:36 pm
Re: pointers and containers
I GET the pointer corectly, the problem is that variables and other things are messed up, i just write the code above badly
-
- Goblin
- Posts: 210
- Joined: Mon Dec 12, 2011 12:52 pm
- Location: Germany
- x 34
Re: pointers and containers
could it be that you delete the object you are pointing to at some time between storing and accessing?
A little bit more of your code would also help to figure out the porblem.
A little bit more of your code would also help to figure out the porblem.
-
- Halfling
- Posts: 91
- Joined: Sat Aug 06, 2011 8:38 am
- Location: United Kingdom
- x 2
Re: pointers and containers
Possibly stupid question but sometimes easily missed, are the setter and fetcher in the same library/executable? If not, make sure everything is cleanly rebuilt to the same headers.
-
- Kobold
- Posts: 35
- Joined: Sat Nov 05, 2011 12:18 am
Re: pointers and containers
How do you create the object? With new?