3
hidden
2y

Why the fuck is it not possible to pass a pointer to a multidimensional array in C++? Like who the fuck though a pointer to a pointer to an array was an elegant solution? I still can’t get my head around how to access the fucking array!!! And this is for a project too that solves poisons equation using the finite difference method none of which was EVER explained!!! Does anyone have a clue about this??????

Comments
  • 1
    You can do this

    Declare:
    int x[2][3];

    Function prototype:
    void func( int (*arr)[2][3] );
  • 5
    The important thing to remember is that in c++ multidimensional arrays are squashed into a single dimensional array. So x[1][2] is translated to *( x + 1 * 3 + 2 )

    So actually these things mean nothing without the full dimensions. Really you only need the second dimension, so actually I think:

    int (*arr)[][3]; is legal and the outer dimension can be indeterminate.

    But these are not arrays of pointers to arrays, and the parenthesis around the name is how the syntax separates arrays of pointers and pointers to arrays

    Let me know if you have questions
Add Comment