float x[size][2];
This does not work because declared arrays cannot have run-time sizes. Try the vector:
std::vector< std::array<float, 2> > x(size);
Or use a new one
// identity<float[2]>::type *px = new float[size][2]; float (*px)[2] = new float[size][2]; // ... use and then delete delete[] px;
If you don't have C ++ 11, you can use boost::array instead of std::array .
If you don't have a raise, make your own array type, which you can insert into the vector
template<typename T, size_t N> struct array { T data[N]; T &operator[](ptrdiff_t i) { return data[i]; } T const &operator[](ptrdiff_t i) const { return data[i]; } };
To loosen new syntax, you can use the identity template, which is actually a built-in typedef (also available in boost )
template<typename T> struct identity { typedef T type; };
If you want, you can also use the vector std::pair<float, float>
std::vector< std::pair<float, float> > x(size);
Johannes Schaub - litb
source share