Cannot convert (*)[] to **

后端 未结 2 701
走了就别回头了
走了就别回头了 2021-02-04 16:56

If I create a file:

test.cpp:

void f(double **a) {

}

int main() {
    double var[4][2];
    f(var);
}

And then run: g++ test.cpp -o t

2条回答
  •  忘掉有多难
    2021-02-04 17:16

    The problem is that a double** is a pointer to a pointer. Your 'f' function wants to be passed the address of a pointer to a double. If you call f(var), well, where exactly do you think that pointer is? It doesn't exist.

    This will work:

    double *tmp = (double *) var;
    f (&tmp);
    

    Also, it would work to change the definition of f:

    void f (double a[4][2]) { }
    

    Now f takes a pointer to the kind of array you have. That will work.

提交回复
热议问题