Jump to content

  • Log In with Google      Sign In   
  • Create Account

#ActualAzaral

Posted 18 April 2013 - 12:18 PM

Yeah, you store a reference in a pointer.

Instead of

 

Thing &myThing = tempVector[i];

 

you want

 

Thing* myThingPointer = &tempVector[i];


A pointer stores a memory address. A reference is a memory address. This means myThingPointer will point to whatever is at the memory addres that is tempVector[i] currrently. Becareful: If the vector reconfigures itself, myThingPointer might not point to what you think it is anymore. It will still be pointing at the same address, but the contents of that address won't be the same. It could be anything.


#1Azaral

Posted 18 April 2013 - 12:17 PM

Yeah, you store a reference in a pointer.

Instead of

Thing &myThing = tempVector[i];

 

you want

Thing* myThingPointer = &tempVector[i];


A pointer stores a memory address. A reference is a memory address. This means myThingPointer will point to whatever is at tempVector[i]. Things to be careful of: If the vector gets a new heap assignment because it grew, myThingPointer might not point to what you think it is anymore.

PARTNERS