In C ++, the term "constant expression" specifically refers to an expression whose meaning is known at compile time. This is not the same as the const variable. For example, 137 is a constant expression, but in this code:
int function(int x) { const int k = x; }
The value of k not a constant expression, since its value cannot be determined at compile time.
In your case, you have a data item declared as
const int ilosc_sqrt;
Even if it is marked const , its value is unknown at compile time. It is initialized in the list of initializers as
ilosc_sqrt(sqrt(ilosc))
This value cannot be determined until the program is started, therefore, an error. (Note that the new C ++ 11 constexpr , in particular, is intended to simplify the definition of constant expressions in the source code and provide the ability to more quickly compile compile time with constants.)
To fix this, you will need to either split your initialization into smaller steps:
drugie_pochodne = new double**[ilosc_sqrt]; for (int i = 0; i < ilosc_sqrt; i++) { drugie_pochodne[i] = new double*[ilosc_sqrt]; for (int j = 0; j < ilosc_sqrt; j++) { drugie_pochodne[j] = new double[ILOSC_WARSTW]; } }
Or use a library like Boost.MultiArray that supports the syntax of cleaner initialization.
Hope this helps!
source share