简体   繁体   中英

How to pass array of arrays to a template class with non-type parameters

I would assume the below code would work to initialize the Matrix class, but for Matrix C I get the following:

error C2440: 'initializing': cannot convert from 'initializer list' to 'Math::Linear::Matrix<int,2,2>'

        template<class T, unsigned int Rows, unsigned int Cols>
        class Matrix
        {
        public:
            Matrix(std::array<std::array<T,Cols>,Rows> ArrayArray)
            {
            
            }
        }

    std::array<std::array<int, 2>, 2> A = {{ {{1,1}} , {{1,1}} }};
    Matrix<int, 2, 2> B = A;
    Matrix<int, 2, 2> C = {{ {{1,1}} , {{1,1}} }};

To use initializer list initialization, you need one more { } .

std::array<std::array<int, 2>, 2> A = {{ {{1,1}} , {{1,1}} }}  ;
Matrix<int, 2, 2> C =               { {{ {{1,1}} , {{1,1}} }} };

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM