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

Storing an object in a struct

Started by bedtime Oct 26, 2012 at 4:06 PM 1 replies 1.1k views
Original Post
bedtime
bedtime
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?
SiCrane
SiCrane
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.
bedtime
bedtime

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. :/

Topic Locked

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

Sign in to reply to this topic.