C++ casting static two-dimensional double array to double**

前端 未结 2 1768
隐瞒了意图╮
隐瞒了意图╮ 2021-02-14 18:55

I have such matrix in my program:

double m[3][4] = 
    {
        {2, 4, 5, 7},
        {4, 5, 1, 12},
        {9, 12, 13, -4}
    };

And I\'d

相关标签:
2条回答
  • 2021-02-14 19:17

    You can't just cast the array. You are going to have to create something like this:

    double m[3][4] = 
        {
            {2, 4, 5, 7},
            {4, 5, 1, 12},
            {9, 12, 13, -4}
        };
    
    double *marray[3] = {m[0],m[1],m[2]};
    calculate(marray,3);
    

    Or you can use a loop:

    const size_t n = 3;
    double *marray[n];
    for (size_t i=0; i!=n; ++i) {
        marray[i] = m[i];
    }
    calculate(marray,n);
    
    0 讨论(0)
  • 2021-02-14 19:21

    You can't.

    The notation double** refers to an array of pointers. You don't have an array of pointers, you have an array of arrays of doubles.

    0 讨论(0)
提交回复
热议问题