I have the following template class:
#ifndef T_SIMPLE_MATRIX_H
#define T_SIMPLE_MATRIX_H
template<class T, int N>
class SMatrix {
private:
T v[N*N];
public:
SMatrix<T, N>(){}
T& operator() (int r, int c){
return v[N*r+c];
}
const T& operator()(int r, int c) const{
return v[N*r+c];
}
};
#endif //
And the following main code:
ifstream fi(argv[1]);
int N;
fi >> N;
for (int i = 0; i < N; i++) {
int M;
fi>>M;
cout << "Matrix size " << M << endl;
SMatrix<double, M> A;
}
This code fails at main.cpp and gives the error: "non-type template argument of type 'int' is not an integral constant expression". It works when I change M to 2, what can I do to pass ifstream value to the template?