What are you trying to do?? I defined a struct and plugged it in for float:
-
struct hello {};
-
hello **matrix;
-
int rows = 10, cols = 10;
-
matrix = new hello* [rows];
-
for(int i = 0; i<rows; i++)
-
{
-
matrix [i] = new hello [cols];
-
}
-
and it compiles fine.
If you are trying to allocate a 2D array of your struct, you do it this way:
-
-
hello (*matrix)[10] = new hello[10][10];
-
In this second case matrix is a pointer to an array of 10 hello (your struct).
Remember, C++ really doesn't have 2D arrays. It has one-dimensional arrays. The value between the first pair of brackets is the number of elements in the array. Values between other brackets are just defining the element type.
-
char arr[10]; //arr has 10 elements. Each element is a char
-
char arr1[10][10]; //arr1 has 10 elements. Each element is an array of 10 char.
-
So, in C++ the name of the array is the address of element 0. That means the name "arr" is the address of element 0 making "arr" a char*. You can allocate this array by:
-
char* arr = new char[10];
-
Continuing, "arr1" is the address of element 0, which is an array of 10 char.
That makes "arr1" the address of an array of 10 char. You can allocate this array but you have to declare a pointer to an array of 10 char for the address returned by new:
-
char (*arr1)[10] = new char[10][10];
-