Hello there,
I want to create a struct that can point to a number of other structs (basically a tree consisting of different vertexes).
This is what I tried:
// define a struct-type named "Body_Struct"
typedef struct {
int Volume;
int Mass;
} Body_Struct;
// Initializes a Body_Struct and sets the pointer Ptr_Slot1 to it
Body_Struct* Ptr_Slot1 = {Volume = 10; Mass = 10;}
// Initializes a Body_Struct and sets the pointer Ptr_Slot2 to it
Body_Struct* Ptr_Slot2 = {Volume = 20; Mass = 20;}
// define a second struct-type named "Geometry_Struct"
typedef struct {
int Price;
struct Body_Struct* Pointer1;
struct Body_Struct* Pointer2;
} Geometry_Struct;
Geometry_Struct Geometry1;
Geometry1.Price = 99.95;
Geometry1.Pointer1 = Ptr_Slot1;
Geometry1.Pointer2 = Ptr_Slot2;
Every time I try to write/read a value via
Geometry_Struct.Pointer1.Mass the engine returns a pointer-error and crashes.
So apparently the pointer are not set up correctly.
I don't understand what I did wrong though.
(already checked the help/manual/forum search).
The way I understand it, this line:
Body_Struct* Ptr_Slot2 = {Volume = 20; Mass = 20;} a) Creates a new struct of type Body_Struct
b) Assigns a pointer named Ptr_Slot2 to this struct-instance
c) Accesses the newly created struct via the pointer
d) and assigns Ptr_Slot2.Volume = 20 and Ptr_Slot2.Mass = 20
I get the same error when using an array of pointers in the Geometry struct where each pointer points to a different struct and then using:
Geometry1.Array[2].Mass Any help is greatly appreciated.
Have a nice evening.