Stack Overflow when declaring array
Hello,
I have a class, MyClass, which contains a 2-dimensional array, my_array, of a structure of type MyStruct. Below is the code I have used to implement this :
Code:
struct MyStruct
{
int u;
int v;
int w;
int x;
int y;
int z;
};
class MyClass
{
private:
MyStruct my_array[1000][500];
};
void main()
{
MyClass my_class;
}
However, when I compile this, I get a compiler error indicating "stack overflow". I'm a bit of a rookie, but from what I gather this is because when I create the my_struct array, I am creating it directly onto the stack, rather than the heap. And, seeing as my_struct contains a large number of MyStructs, each of which contains 6 ints, then that is a lot of data to be stored on the stack, causing an overflow.
But I don't know how to do this any other way, and I don't really understand which elements of the program are created in the stack, and which are created on the heap.
I have tried defining MyClass without telling it to explicitely create all of the elements of the array:
Code:
class MyClass
{
private:
MyStruct my_array[][];
};
But I get the error: "error C2087: 'my_array' : missing subscript"
All I want to do is let my program know that this array will exist, but I don't need to create all the elements of the array right at the start of the program do I? And they certainly shouldn't be put on the stack, as I will need to refer to them throughout the program...
This whole stack / heap thing is getting me down, please could