Can a function return value be used in declaring an array

Hi guys, is this valid C++14?

1
2
3
4
5
6
7
8
9
10
11
12
int factorials[10] = {
    factorial(0),
    factorial(1),
    factorial(2),
    factorial(3),
    factorial(4),
    factorial(5),
    factorial(6),
    factorial(7),
    factorial(8),
    factorial(9)
 };


1
2
3
4
5
6
7
8
static int factorial(int n)
{
 int fact = 1;
 for (int i = 2; i<=n; i++) {
  fact = fact * i;
 }
 return fact;
}
Yes. And it's valid C++98, as far as I know.
The individual elements don't need to be compile-time constants, just the size of the array itself.
Last edited on
oh...okay thanks
Topic archived. No new replies allowed.