Passing a three-dimensional array by reference in C ++

The function is defined as:

int strip(double *signalstnV){
.
.
return 0;
}

And the main function is called:

main{
.
.
double signalstnV[iteration][2*range+1][3];
.
.
check = strip(signalstnV);
.
}

I wanted to use an array in the next function in main after it was changed in the strip function. But during compilation I get an error message like

sim.C: In the function 'int main (int, char **):

sim.C: 54: 26: error: cannot convert 'double () [151] [3] to' double for argument '1 to' int strip (double *)

check = strip (signalstnV);

I can’t figure it out. Please help. My main goal is to create an array from the strip function and pass it to other functions later in the code.

Also, when I used this array in another function

threshold(double * signalstnV)

and using the for loop to extract some specific values, it gives an error like:

invalid types ‘double[int]’ for array subscript 
if (signalstnV[k][j][3] < -0.015){
..}
+4
3

. , 2- .

"-" , :

check = strip(&signalstnV[0][0][0]);
+5

- :

//double signalstnV[iteration][2*range+1][3];
using IterationValues = double[iteration];
using IterationRangesValues = IterationValues [2*range+1];
//...

, , :

IterationRangesValues signalstnV[3];
check = strip(signalstnV);

: strip(IterationRangesValues * matrix) this strip(IterationRangesValues (& matrix)[3]). , typedef.

std::array:

using IterationValues = std::array<double, iteration>;
using IterationRangesValues = std::array<IterationValues, 2*range+1>;
//...
+2

, :

template<size_t X, size_t Y, size_t Z>
int strip( double(&strip)[X][Y][Z] )
{
}

.

If you need to support only one size, delete the line templateand replace X Y Zwith the actual sizes that you need to support.

0
source

Source: https://habr.com/ru/post/1658429/


All Articles