jeudi 3 mars 2016

How do I set a constexpr variable to an ordinary variable?

I'm making a two dimensional array, a dynamic array containing several static arrays (of shorts):

constexpr unsigned char constColumnMax = columnMax; //wrong
using column = std::array<short, constColumnMax>;
column * row = new column[rowMax];
row[0][0] = 10;

Where columnMax is an unsigned char that has a value set by a previous function, the column definition makes up the static arrays, & the row array is a dynamic array of columns.

The problem with this is that my code to set the constexpr, constColumnMax equal to columnMax is wrong. However, the variable that I put into std::array<> has to be the constexpr type.

I'm at a dead end here. The only thing I can think of is using a loop to increment constColumnMax which won't work for obvious reasons. Any help you guys can give would be greatly appreciated.

Aucun commentaire:

Enregistrer un commentaire