Creating some arrays
Hi
I''m at the moment coding a routine, where i''m going trough a cycle of faces that are stored in an array.
The purpose of that routine, is to check if a face is inside a cube. If it is, i increment a variable, otherwise not.
So, in result i will get a number!
Now, i want to create an array inside a structure, to hold that list of faces.
I could do it with linked lists, but i wanna try with arrays, so, is this possible ?
Structure:
typedef struct portais
{
int num;
Faces data;
float planex[2];
float planey[2];
float planez[2];
struct portais *next;
}*portals;
portals init_portals;
portals next_portals;
the above is my data structure, so i wanna add an array to that structure at runtime.
something like this:
Faces *Temp = new Temp[number_of_faces];
next_portals->dados = Temp;
well you cant create an array like normal if it isnt a constant size. for some reason, you just cant. even tho you should. but.. you can still do it.
the structure must be kept a constant size, so you need to use a pointer to the array instead of having the array inside the structure. to do this then the pointer points to the first item. when initializing the structure (use classes btw) just do something like:
Faces *Data = malloc( sizeof(Faces) * number_of_faces );
maybe what you suggested to yourself would work (with the ''new'' keyword) but i dont use ''new'' and ''delete'' cause i really just prefer malloc() and free().
the structure must be kept a constant size, so you need to use a pointer to the array instead of having the array inside the structure. to do this then the pointer points to the first item. when initializing the structure (use classes btw) just do something like:
Faces *Data = malloc( sizeof(Faces) * number_of_faces );
maybe what you suggested to yourself would work (with the ''new'' keyword) but i dont use ''new'' and ''delete'' cause i really just prefer malloc() and free().
(http://www.ironfroggy.com/)(http://www.ironfroggy.com/pinch)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement