I have the following code:
template <int Size>
class A
{
public:
static int size;
static int myArray[Size];
};
The size variable I can set by:
template <int Size>
int A<Size>::size=SomeQuantity;
I would like to initialize the array from 0...Size in steps of 1. E.g, if Size=10, myArray =[0,1,2,....,9]
Can the initialization of a static array be assigned to a function? Is there any C++ built in way of doing this?
Edit I could define inside the class:
static int initArray()
{
for( int i = 0; i<sizeof(myArray)/sizeof(myArray[0]); i++)
{
myArray[i]=i;
}
return 0;
}
And afterwards initialize this as:
template <int Size>
int A<Size>::myArray[Size]={initArray()};
Kind regards