Storing an object in a struct

Started by
1 comment, last by bedtime 11 years, 6 months ago
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?
Advertisement
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.

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

This topic is closed to new replies.

Advertisement