Sign in to follow this  

Storing an object in a struct

This topic is 1908 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

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

[CODE]
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??
[/CODE]

Any suggestion?

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites
[quote name='SiCrane' timestamp='1351267997' post='4994184']
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.
[/quote]
Thanks. That worked!

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

Share this post


Link to post
Share on other sites

This topic is 1908 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this