Jump to content
  • Advertisement
Sign in to follow this  
ballack

basic question

This topic is 4728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

hi every one. i have a very basic doubt. can i have a structure like: struct tank { .... ..... }*t[6]; and use t[1]->member; t[2]->member; ?

Share this post


Link to post
Share on other sites
Advertisement
I think it is a little more like:


struct tank
{
...
}

tank *t[6];

t[0]->mMember;
t[1]->mMember;


Hope that helps. :)

Edit: My apologies as the above is actually wrong as pointed out. I forgot to use the * in my code. Fixed now. :)

[Edited by - JWindebank on June 14, 2005 3:39:57 AM]

Share this post


Link to post
Share on other sites
lets clean that up abit and look at it.


struct Thing
{
int a;
//more member..
};

Thing *tp[10]; //this is an array of Pointers to Thing's

Thing t[10]; //this is an array of Thing's

//two ways to dereference tp
tp[1]->a = 1;
*tp[1].a = 1;

//assigning to a member of a non-pointer
t[1].a = 1;

//pointing the array at a new array
tp = t;

//making a pointer in the array point to a Thing
Thing st;

tp[2] = &st;


hope I didnt confuse ya or f-that up too bad ;D

JWind is incorrect I believe. -> is for dereferencing pointer's to structs.
. is for dereferencing plain old structs.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
ballack, Yes you can...
JWindback, you should use '.' instead of '->' if you intend no to use pointers !!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!