I am trying to cretate an array of doubles in pi_sequence and then return a pointer to it. Then I want to print out its values. I tried this but I get the error storage size of ests is not constant:
#include <iostream>
#include <stdlib.h>
double* pi_sequence(const int& len)
{
static double ests[len];
ests[0] = 1.11;
ests[1] = 2.22;
return ests; // address of?
}
int main() {
double* ests = pi_sequence();
std::cout << "will write to file: " << ests[0] << std::endl;
}
lenis always 2 anyway, since you assign toests[0]andests[1]so I have a hard time understanding what you actually want to do.std::vectorconstexprand templates will let you do sophisticated calculations are compile time. But if you need it to depend on user input you will need to use another approach, maybe just returning anstd::vector<double>.new[]orstd::vector