I am trying to initialize an array of size n based off the input argument of my constructor. This works:
//Inside Header
class runningAverage{
private:
byte n;
float array[10];
public:
runningAverage(byte);
};
//Inside .cpp
runningAverage::runningAverage(byte a){
n = a;
for (byte i = 0; i<n; i++) {
array[i] = 0;
}
}
and this does not work:
//Inside Header
class runningAverage{
private:
byte n;
float array[];
public:
runningAverage(byte);
};
//Inside .cpp
runningAverage::runningAverage(byte a){
n = a;
for (byte i = 0; i<n; i++) {
array[i] = 0;
}
}
I want to initialize the array so that is the size specified by n. This way I don't waste memory by arbitrarily specifying float array[256] or something like that. Any help is appreciated!