Using a class member directly in the header file

Good afternoon,

I'm trying to use a class member to initialize the dimension of a matrix.
I have two issues. Here is the code (.h) simplified :

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#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 ?

Thank you,

Regards,
C.
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
Topic archived. No new replies allowed.