Structs inside Classes (I've gave 2 Answers, but which is right?)

Hey guys, I simple want to know if this would work in my Object class or if I would have to declare an instance of the structs within my class?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#include <string>

#define PREV_OBJECT 0
#define NEXT_OBJECT 1
#define LAST_OBJECT 2

class Object{
  private:
    struct idPropeties{
        const int id;//Object setup id, must always be set for all registered data to load
        const string type;//Type of Object i.e. Mob; Scene; Other;
        const string name;//Name of the Object (for in-game use and clarity)
        const string image;//Name of the image file for the Object
        const float sizeBounds[4]; //Size and shape --- 0=maxX; 1=maxY; mins will always be 0;
        const float mass; //Object mass/kg --- Wall = 100; Player = 50;
        const float friction; //Decceleration for Object passing over
    };
    struct objectList{    
        Object* nextObject;//Used to create an internal list between Objects
        Object* prevObject;//Used to create an internal list between Objects
        static Object * lastObject[6];//A LAST Object for each layer
        void removeFrom();//remove Object from Internal-List
        void addTo(int arg);//addObject to Internal-List
    };
    struct posPropeties{
        int layer; //Collision Layer --- 0=disabled; 1=BG; 2=scene; 3=common; 4=sceneGhost; 5=fullGhost
        float pos[3]; //Pos & Rot --- 0=BLx; 1=BLy; 2=IMAGE rotation
        float speed[2]; //X velocity; Y velocity; 1m/s = 1 Scenery block past per second
        float hitBounds[2][4]; //[x|y][mm, mM, Mm, MM]
        bool isCollidable;//If the Object is Collidable
        bool staticHit;
        void updateHitBounds();//set new hitBounds (hitBounds is also Object postition)
    };
  public:
    //Rest of class Object not relevant for this question//
};


So using the above code would I be able to edit the position of my Object using
 
Object::posPropeties.pos[<x|y|r>] = <val>;

OR would I have to make an instance of these classes within my object like
1
2
3
4
//Inside Object:Private//
    posPropeties posProps;
//Outside Object//
Object::posProps.pos[<x|y|r>] = <val>;

Please don't tell me that it wouldn't work because the value's private, I do know this and yes I know I'll need public class function (which I already have) todo this (or of course a friend-ed function, but I don't need that).

So, Which will I need? (I hope it's the former somehow)
Last edited on
defining a class/struct inside another class/struct isn't anything special. The only thing that's different is adding a level of scope and visibility from outside.

So yes: you need an instance of an interior class/struct in order to access non static members. Just as any other class/struct
Thanks pal, I was afraid I would :)
Shouldn't really be a problem though, I just wasn't sure which code snippet to use.
Cheers!
Topic archived. No new replies allowed.