Jump to content

  • Log In with Google      Sign In   
  • Create Account

FREE SOFTWARE GIVEAWAY

We have 4 x Pro Licences (valued at $59 each) for 2d modular animation software Spriter to give away in this Thursday's GDNet Direct email newsletter.


Read more in this forum topic or make sure you're signed up (from the right-hand sidebar on the homepage) and read Thursday's newsletter to get in the running!


Pointers and STL containers


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 tifkagh   Members   -  Reputation: 122

Like
Likes
Like

Posted 17 February 2002 - 03:40 AM

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.

Sponsor:

#2 SabreMan   Members   -  Reputation: 504

Like
Likes
Like

Posted 17 February 2002 - 03:54 AM

You need to dereference the pointer. Use the form

(*ivMap)[someInt]


--
Very simple ideas lie within the reach only of complex minds.

#3 Kylotan   Moderators   -  Reputation: 3338

Like
Likes
Like

Posted 17 February 2002 - 05:30 AM

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 ]




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS