#include <vector>
#include <array>
#include <typeinfo>
template<typename T, std::size_t N>
struct md_vector
{
using type = std::vector<typename md_vector<T, N - 1>::type>;
};
template<typename T>
struct md_vector<T, 1>
{
using type = std::vector<T>;
};
template<typename T, std::size_t N>
using md_vector_t = typename md_vector<T, N>::type;
class OptimalSamplingStrategy{
public:
///Constructors
OptimalSamplingStrategy(int _nbMorph);
///Destructor
~OptimalSamplingStrategy();
int _nbMorph;
md_vector_t<double, 2*_nbMorph+1> _OptimalSamplingStrategyMatrix; ///error
}
error: invalid use of non-static data member ‘OptimalSamplingStrategy::_nbMorph’|
I can't use a class member directly in the header file (here _nbMorph).
It was an issue I got before and that I didn't solve as I succeed in finding other ways. I don't think it's possible here.
Do somebody could explain to me what is going on ?
Template parameters should be known at compile-time. You cannot choose them at runtime.
If you need array-like class with dimensions set in runtime, you will need to create class implementing such behavior yourself.
Read on mimicing multidimensional arrays with 1D array here http://www.cplusplus.com/forum/articles/17108/#msg85595