Skip to main content
GameDev.net gamedev.net
🔒 Locked

Pointers and STL containers

Started by tifkagh Feb 17, 2002 at 9:40 AM 1 replies 500+ views
Original Post
tifkagh
tifkagh
Given the defintition;
  
struct
{
	// In Game BOBs

	lpBOB			mousepointer;
	lpBOB			sheep;
	lpCharacter		player;
	lpGSTATE		gstate;
	//iCOORD			test;

} GameG ; 
  
and that the GSTATE class contains an object map of type vector. I use the following declarations to create a pointer to the vector:
  
GameG.gstate = new GSTATE(iTempWidth, iTempWidth);
vector<int>* ivMap = &GameG.gstate->map;
  
What does ivMap really point to? I was expecting ivMap[someint] to return the contents of the approipriate location within the gstate->map array/vector. Instead I get goobledigook.
SabreMan
SabreMan
You need to dereference the pointer. Use the form

(*ivMap)[someInt]


--
Very simple ideas lie within the reach only of complex minds.
Kylotan
Kylotan
You can''t just treat the address of a vector as the same thing as the address of an array. Instead, use the address of the first element of the vector.

You should probably also give that struct a typename, for clarity.

[ MSVC Fixes | STL | SDL | Game AI | Sockets | C++ Faq Lite | Boost ]

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.