Quote:
|
I can't see where it comes from.
|
Using a debugger (such as gdb) would help with this.
Quote:
|
I am trying to declare a two dimensional array without giving it any size.
|
Well, there's your problem. This is not the way things are done in C or C++.
C and C++ will not do anything that you don't explicitly tell them to do. If you don't say "allocate memory for my two dimensional array of size X by Y", they won't... and you haven't. Besides, even if C++ were designed to do this sort of allocation for you, the math necessary to translate a two-dimensional coordinate into a one-dimensional memory address requires the size of at least one of the dimensions to be known, and you aren't specifying that either.
Now, look at the line in your code which you intend to allocate an array with:
You are not creating a new int array, you are creating a new **int: a pointer to a pointer to an int. On a typical 32-bit machine, you've just allocated only 4 bytes of memory.
This is the source of your segmentation fault, since you eventually try to access memory that hasn't been allocated (the usual meaning of a segmentation fault).
You could accomplish what you're trying to do with a vector of vectors, or by using the new operator properly (the method I'd recommend, since the dimensions of your array are apparently known before you enter the nested for-loops).
I suggest finding a good C++ tutorial through google, or check out cppreference.com if you need a quick reference to some of the STL classes like vector (I've got it bookmarked). There are also plenty of good C++ books out there that could teach you these things.