I have a simple function that populates an array with double values and returns the array:
double create_step_vectors(int n_steps, double step_size)
{
std::array<double, n_steps + 1> vec{};
for (int i = 0; i <= n_steps; i++)
{
arr[i] = i * step_size;
}
return arr
}
I pass in n_steps which is defined in main scope as:
constexpr int n_step {static_cast<int>(1 / x_step) };
I get the error:
error: 'n_steps' is not a constant expression
13 | std::array<double, n_steps + 1> vec{};
I have tried to put n_steps + 1 in curly brackets which didn't help. The purpose of n_steps, where the error occurs, is to set the size of the array, arr.
How could I solve this issue?