I have a structure that has an array.
struct Page_Directory {
public:
int numEntries;
int nextDirPage;
int [] array;
};
However, I always want this array to be of certain length, so that the size of this structure is always 4 + 4 + 100*4 bytes.
I don’t want to have a structure declaration like following:
struct Page_Directory {
public:
int numEntries;
int nextDirPage;
int *array;
};
since size of this structure is 4 + 4 + 4 = 12 bytes (even if I allocate memory to entries by using new or malloc).
Now, how do I achieve this? I can’t put a declaration like the first one in header file, you don’t put array size details in the header file, only what each member’s type.
If you always want the array to have a certain size then there is no way around
declaring it with a certain size: