I want to manipulate a queue of multi dimensional array (matrice), I am not interested in std since my cross compiler is not fully supporting C++20
queue<float**> q;
float A[2][3] = {{0, 1, 2}, {10, 20, 30}};
printf("Value from array %f\n", A[1][1]);
q.push( (float**) A );
printf("Array A added to the queue \n");
printf("Value from the queue %f\n", q.front()[1][1]);
Here's the output:
Value from array 20.000000
Array A added to the queue
Segmentation fault (core dumped)
I also tried with queue<float*> q;
queue<float*> q;
float A[2][3] = {{0, 1, 2}, {10, 20, 30}};
printf("Value from array %f\n", A[1][0]);
q.push( (float*) A );
printf("Array A added to the queue \n");
printf("Value from the queue %f\n", ((float**)q.front())[1][1]);
I an getting the sane result
The error is because of the fact that float[2][3] cannot be directly converted into float**.float** means it expects an array of float*. If you want to use directly it in queue , you can use a pointer to the array itself and declare queue as holding pointers of array of size [2][3] in this format
queue<float(*)[3]>q;
queue<float(*)[3]> q;
float A[2][3] = {{0, 1, 2}, {10, 20, 30}};
printf("Value from array %f\n", A[1][1]);
q.push(A);
printf("Array A added to the queue \n");
printf("Value from the queue %f\n", q.front()[1][1]);
This gives the output as Output: