how to assign an array from an initializer list
I have a limited knowledge about c++. I tried to compile a c++ library and when I run the make file for the following header file
mcmc_dhs.h
#include <algorithm>
#include <map>
// intrinsic shape and (reduced) shear just add?
//#define WLNOISE
// use shear instead of reduced shear for model
//#define NOREDSHEAR
/// parameters for the M200-concentration relation
const number mcreal[2] = {9.59,-0.102}; // Dolag et al. (2004)
//const number mcreal[2] = {5.26,-0.100}; // Neto et al. (2007) [Millenium Run]
/// critical density at z=0 (h100=1) in [Msun/Mpc^3]
const number rhocrit = exp(log(rhoCrit)+3.*log(Mpc)-log(Msun));
/// two extra halo parameters: r200 (and concentration: 2)
#define PARAMS 1
/// define region (square; twice value here) about halo that considers sources for model
#define REGION 10.0*arcmin
class mcmc_dhs : public mcmc
{
public:
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}};
}
~mcmc_dhs() {}
/// size of grid for looking up sources
static const int Ngrid = 200;
It returns the following error message:
mcmc_dhs.h:55:67: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
mcmc_dhs.h:55:17: error: assigning to an array from an initializer list
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
In file included from ../modules/matrix.h:15:0,
from ../modules/probdensity.h:4,
from ../modules/mcmc.h:4,
from mcmc_dhs.h:4,
I would appreciate if someone can help.
c++ arrays initializer-list
|
show 1 more comment
I have a limited knowledge about c++. I tried to compile a c++ library and when I run the make file for the following header file
mcmc_dhs.h
#include <algorithm>
#include <map>
// intrinsic shape and (reduced) shear just add?
//#define WLNOISE
// use shear instead of reduced shear for model
//#define NOREDSHEAR
/// parameters for the M200-concentration relation
const number mcreal[2] = {9.59,-0.102}; // Dolag et al. (2004)
//const number mcreal[2] = {5.26,-0.100}; // Neto et al. (2007) [Millenium Run]
/// critical density at z=0 (h100=1) in [Msun/Mpc^3]
const number rhocrit = exp(log(rhoCrit)+3.*log(Mpc)-log(Msun));
/// two extra halo parameters: r200 (and concentration: 2)
#define PARAMS 1
/// define region (square; twice value here) about halo that considers sources for model
#define REGION 10.0*arcmin
class mcmc_dhs : public mcmc
{
public:
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}};
}
~mcmc_dhs() {}
/// size of grid for looking up sources
static const int Ngrid = 200;
It returns the following error message:
mcmc_dhs.h:55:67: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
mcmc_dhs.h:55:17: error: assigning to an array from an initializer list
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
In file included from ../modules/matrix.h:15:0,
from ../modules/probdensity.h:4,
from ../modules/mcmc.h:4,
from mcmc_dhs.h:4,
I would appreciate if someone can help.
c++ arrays initializer-list
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
@MikeMB the error per se it's not because of lack of support forc++11
. Even with-std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as astd::initializer_list
(even if you don't compile with-std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).
– vsoftco
May 11 '15 at 23:46
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50
|
show 1 more comment
I have a limited knowledge about c++. I tried to compile a c++ library and when I run the make file for the following header file
mcmc_dhs.h
#include <algorithm>
#include <map>
// intrinsic shape and (reduced) shear just add?
//#define WLNOISE
// use shear instead of reduced shear for model
//#define NOREDSHEAR
/// parameters for the M200-concentration relation
const number mcreal[2] = {9.59,-0.102}; // Dolag et al. (2004)
//const number mcreal[2] = {5.26,-0.100}; // Neto et al. (2007) [Millenium Run]
/// critical density at z=0 (h100=1) in [Msun/Mpc^3]
const number rhocrit = exp(log(rhoCrit)+3.*log(Mpc)-log(Msun));
/// two extra halo parameters: r200 (and concentration: 2)
#define PARAMS 1
/// define region (square; twice value here) about halo that considers sources for model
#define REGION 10.0*arcmin
class mcmc_dhs : public mcmc
{
public:
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}};
}
~mcmc_dhs() {}
/// size of grid for looking up sources
static const int Ngrid = 200;
It returns the following error message:
mcmc_dhs.h:55:67: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
mcmc_dhs.h:55:17: error: assigning to an array from an initializer list
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
In file included from ../modules/matrix.h:15:0,
from ../modules/probdensity.h:4,
from ../modules/mcmc.h:4,
from mcmc_dhs.h:4,
I would appreciate if someone can help.
c++ arrays initializer-list
I have a limited knowledge about c++. I tried to compile a c++ library and when I run the make file for the following header file
mcmc_dhs.h
#include <algorithm>
#include <map>
// intrinsic shape and (reduced) shear just add?
//#define WLNOISE
// use shear instead of reduced shear for model
//#define NOREDSHEAR
/// parameters for the M200-concentration relation
const number mcreal[2] = {9.59,-0.102}; // Dolag et al. (2004)
//const number mcreal[2] = {5.26,-0.100}; // Neto et al. (2007) [Millenium Run]
/// critical density at z=0 (h100=1) in [Msun/Mpc^3]
const number rhocrit = exp(log(rhoCrit)+3.*log(Mpc)-log(Msun));
/// two extra halo parameters: r200 (and concentration: 2)
#define PARAMS 1
/// define region (square; twice value here) about halo that considers sources for model
#define REGION 10.0*arcmin
class mcmc_dhs : public mcmc
{
public:
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}};
}
~mcmc_dhs() {}
/// size of grid for looking up sources
static const int Ngrid = 200;
It returns the following error message:
mcmc_dhs.h:55:67: warning: extended initializer lists only available with -std=c++11 or -std=gnu++11 [enabled by default]
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
mcmc_dhs.h:55:17: error: assigning to an array from an initializer list
boundaries = {{0,512},{0,512},{0.01,5.},{100.,3000.},{0.1,50}};
^
In file included from ../modules/matrix.h:15:0,
from ../modules/probdensity.h:4,
from ../modules/mcmc.h:4,
from mcmc_dhs.h:4,
I would appreciate if someone can help.
c++ arrays initializer-list
c++ arrays initializer-list
edited May 11 '15 at 23:13
Dalek
asked May 11 '15 at 22:47
DalekDalek
1,66862455
1,66862455
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
@MikeMB the error per se it's not because of lack of support forc++11
. Even with-std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as astd::initializer_list
(even if you don't compile with-std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).
– vsoftco
May 11 '15 at 23:46
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50
|
show 1 more comment
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
@MikeMB the error per se it's not because of lack of support forc++11
. Even with-std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as astd::initializer_list
(even if you don't compile with-std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).
– vsoftco
May 11 '15 at 23:46
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
@MikeMB the error per se it's not because of lack of support for
c++11
. Even with -std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as a std::initializer_list
(even if you don't compile with -std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).– vsoftco
May 11 '15 at 23:46
@MikeMB the error per se it's not because of lack of support for
c++11
. Even with -std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as a std::initializer_list
(even if you don't compile with -std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).– vsoftco
May 11 '15 at 23:46
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50
|
show 1 more comment
1 Answer
1
active
oldest
votes
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
}
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30178879%2fhow-to-assign-an-array-from-an-initializer-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
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
}
add a comment |
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
}
add a comment |
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
}
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
}
edited May 11 '15 at 23:01
answered May 11 '15 at 22:51
vsoftcovsoftco
42.8k578178
42.8k578178
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f30178879%2fhow-to-assign-an-array-from-an-initializer-list%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Sounds like your compiler isn't in C++11 compatibility mode (or doesn't support it)? What compiler are you using?
– Michael Dorgan
May 11 '15 at 22:49
possible duplicate of Error: Assigning to an array from an initializer list
– m.s.
May 11 '15 at 22:52
Well, it says, that you have to use the -std=c++11 flag. So why don't you?
– MikeMB
May 11 '15 at 23:26
@MikeMB the error per se it's not because of lack of support for
c++11
. Even with-std=c++11
, you'll still get the same error (not the warning though). You get a warning even in C++98 code, since modern g++ compilers (>=4.9) interpret the braces as astd::initializer_list
(even if you don't compile with-std=c++11
) They consider this as an extension, and it is enabled by default (see the warning message).– vsoftco
May 11 '15 at 23:46
@vsoftco: You are right of course - I should have had a closer look at the code first. But I'd still would recommend using the c++11 flag if possible.
– MikeMB
May 11 '15 at 23:50