Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Storing an object in a struct

4: Adsense

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 bedtime   Members   

159
Like
0Likes
Like

Posted 26 October 2012 - 10:06 AM

I would like to store an object in a struct. This is what I have so far:

struct sectionData
{
unsigned int currentSectionNumber;
unsigned int currentObjNum;
unsigned int sectionNumberToGoIn;
int camFocus;
Object obj;  // this is the object i want to store in the struct. how to do it?
};

// store data too struct
sectionData sectData;

// pushback container
game.sectionInfo.push_back(sectData);

// apply info
sectData.currentSectionNumber = 1;
sectData.currentObjNum = 20;
sectData.sectionNumberToGoIn = 0;
sectData.camfocus = 1;
sectData.Object = gameObject; // ?? not sure what to do here

// retrieve info
how to retrieve Object??

Any suggestion?

#2 SiCrane   Moderators   

11774
Like
2Likes
Like

Posted 26 October 2012 - 10:13 AM

Storing an object type in a struct in C++ works exactly like you would use an int or any primitive. You would reference the member object with the object name rather than the type name. Since you decided to call your Object instance obj. sectData's member Object would be referred to as sectData.obj for reading, writing, forming references and so on.

#3 bedtime   Members   

159
Like
0Likes
Like

Posted 26 October 2012 - 04:55 PM

Storing an object type in a struct in C++ works exactly like you would use an int or any primitive. You would reference the member object with the object name rather than the type name. Since you decided to call your Object instance obj. sectData's member Object would be referred to as sectData.obj for reading, writing, forming references and so on.

Thanks. That worked!

I thought I already tried that but I guess I didn't. :/




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.