I have the struct and a template as below:
template <const int nrow, const int ncol>
struct Mat{
const int row_size = nrow;
const int col_size = ncol;
std::array<std::array<float, ncol>, nrow> mat;
};
I want to sort the matrix produced by Mat
struct, so I did:
int main(int argc, const char * argv[]) {
Mat<3, 3> mat;
mat.mat = {{{1,2,3},{4,5,6},{7,8,9}}};
std::sort(std::begin(mat.mat), std::end(mat.mat),
[](std::array<float, mat.col_size>& c1, std::array<float, mat.col_size>& c2){return c1[0]>c2[0];});
}
However, I get this error:
Non-type template argument is not a constant expression
and this expression,mat.col_size
, in sort is underlined red in XCode.
In the struct I made the col_size
a constant but it did not help. However, if I add static
keyword before it, then it works fine.
Why was there this error and what static
does?