C++ function not returning 2d array

后端 未结 1 1416
甜味超标
甜味超标 2021-01-26 05:21

I am writing a Qt application for matrix arithmetic . I taken input of 2 3x3 arrays in x1 and y1 if int is selected and in x2 and y2 if

相关标签:
1条回答
  • 2021-01-26 05:31

    Regardless of what you may have heard before, arrays are not pointers. A bidimensional array has little to do with a pointer to a pointer, which is your compile issue: there is no way of getting from a 2D array to a pointer-to-pointer.

    If your arrays are fixed size, you can change the signature of the functions to require it (and incidentally build, which is good, right?):

    ?? add(T (&a)[3][3], T (&b)[3][3]);
    

    but you are left with what to return from there... of course the answer is Matrix<T>, right? Adding two matrices returns a matrix, which would indicate that the function you are looking for is more like (as a free function):

    template <typename T>
    Matrix<T> add(Matrix<T> const & lhs, Matrix<T> const & rhs);
    

    Which, of course can be spelled:

    template <typename T>
    Matrix<T> operator+(Matrix<T> const & lhs, Matrix<T> const & rhs);
    

    I would recommend that you create a minimal matrix class (google, you can see many reference implementations) or that you use one from an existing library.

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