c++ - Initialize static array using lambda -


i have template in have static array. trying initialize array using lambda - think not getting initialize :

template <class base> a<base> a<base>::arr[size] = [] ()  {   (int = 0 ; < size; i++)   {     a<base>::arr[i]=a<base>();     std::cout<<"test"<<std::endl;   } }; 

i unable see cout message in console when run executable.

how can initialize array using lambda functionality?

you never called lambda.

the lambda not return anything, initializing return value wouldn't work anyway.

arrays cannot returned.

besides default initialization, array can initialized brace-enclosed list of values (or string literal) not can returned functions (including lambdas).

your loop appears value initialize elements. elements not listed in brace initialization list value initialized, can achieve loop empty brace enclosed list:

template <class base> a<base> a<base>::arr[size] = {}; 

Comments

Popular posts from this blog

python - Operations inside variables -

Generic Map Parameter java -

arrays - What causes a java.lang.ArrayIndexOutOfBoundsException and how do I prevent it? -