If your current compiler does not yet support C ++ 11, you can initialize the contents of the vector using standard algorithms and functors:
class sig { public: sig() { struct Functor { Functor() : value(0) {}; int operator ()() { return value++; }; int value; }; std::generate(p_list, p_list + 4, Functor()); } int p_list[4]; };
The previous example snippet is here .
Yes, it's pretty ugly (at least it looks ugly for me) and doesn't do the work at compile time; but it does the work you need in the constructor.
If you need some other initialization (initialization with even / odd numbers, initialization with random values, beginning with anoter value, etc.), you only need to change the functor, and this is the only advantage of this ugly approach.
PaperBirdMaster
source share