繁体   English   中英

如何将 arrays 数组传递给具有非类型参数的模板 class

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

我假设下面的代码可以初始化矩阵 class,但是对于矩阵 C,我得到以下信息:

错误 C2440:“正在初始化”:无法从“初始化程序列表”转换为“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}} }};

要使用初始化器列表初始化,您还需要一个{ }

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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