pointers and containers

Get answers to all your basic programming questions. No Ogre questions, please!
vblanco
Kobold
Posts: 26
Joined: Thu Jan 26, 2012 8:36 pm

pointers and containers

Post by vblanco »

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
Last edited by vblanco on Fri Mar 09, 2012 10:16 pm, edited 2 times in total.
Shtuka
Greenskin
Posts: 146
Joined: Mon Jan 10, 2011 7:39 pm
x 9

Re: pointers and containers

Post by Shtuka »

Use

Code: Select all

myobject*pobject2 = list.back(); //to get the pointer
vblanco
Kobold
Posts: 26
Joined: Thu Jan 26, 2012 8:36 pm

Re: pointers and containers

Post by vblanco »

I GET the pointer corectly, the problem is that variables and other things are messed up, i just write the code above badly
User avatar
Waruck
Goblin
Posts: 210
Joined: Mon Dec 12, 2011 12:52 pm
Location: Germany
x 34

Re: pointers and containers

Post by Waruck »

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.
zootlewurdle
Halfling
Posts: 91
Joined: Sat Aug 06, 2011 8:38 am
Location: United Kingdom
x 2

Re: pointers and containers

Post by zootlewurdle »

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.
Czar
Kobold
Posts: 35
Joined: Sat Nov 05, 2011 12:18 am

Re: pointers and containers

Post by Czar »

How do you create the object? With new?