How can I assign an array from an initializer list?

You cannot assign directly to an array after its declaration. Basically your code is the same as

int main()
{
    double arr[2][2];
    arr = { {1, 2}, {3, 4.5} }; // error
}

You have to either assign the value at declaration

double arr[2][2] = { {1, 2}, {3, 4.5} };

or use a loop (or std::copy) to assign elements. Since your array seems to be a member variable, you can also initialize it in the constructor initialization list:

 mcmc_dhs() : data(), cosmohandler(0.3,0.7,0.21,0.8,0.04), 
              lenseff(), intrvar(), 
              boundaries{{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}}
 { 
    // rest of ctor implementation
 }

Leave a Comment