int main(){
int sample_rate = 50;
int t_max = 60*5 ;
int dimensions = 3;
int num_samples = sample_rate * t_max;
double data[dimensions][num_samples] = { { } }; //Error here
return 0;
}
I understand that the size of an array on the heap must be known during compile time which it is here (3 x 15000). Why am I still getting the error?
Just use std::vector
instead.
#include <vector>
int main(){
int sample_rate = 50;
int t_max = 60*5 ;
int dimensions = 3;
int num_samples = sample_rate * t_max;
std::vector<std::vector<double>> data(dimensions, std::vector<double>(num_samples));
// access data like this
data[0][0];
return 0;
}
The bound (size) of an array when it is specified has to be a constant-expression as per [dcl.array]/1.
The bounds you have specified are not constant expressions. To convert them into such, you either have to prepend const
or constexpr
(C++11 onward) before the declaration of those four integers like this:
const int sample_rate = 50;
Or
constexpr int sample_rate = 50;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With