lundi 21 janvier 2019

initialize an array of compile-time constant size with incrementing numbers [duplicate]

This question already has an answer here:

I have an array whose size is set using a compile-time constant (a pre-processor #define in my case). I need to initialize it using consecutive numbers. How can I do this?

Simplified example:

#define ARR_SZ = 5
int arr[ARR_SZ] = {0,1,2,3,4}; // This needs to adapt to any number

I can use C++11, but not newer (although I would be interested to learn of newer techniques even if I can't use them for this project)

Aucun commentaire:

Enregistrer un commentaire