【发布时间】:2015-07-22 14:51:31
【问题描述】:
我对 c++ 的了解有限。我试图编译一个 c++ 库,当我为以下头文件运行 make 文件时
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;
它返回以下错误消息:
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,
【问题讨论】:
-
听起来您的编译器不在 C++11 兼容模式下(或不支持)?你用的是什么编译器?
-
嗯,它说,你必须使用 -std=c++11 标志。那你为什么不呢?
-
@MikeMB 错误本身并不是因为缺乏对
c++11的支持。即使使用-std=c++11,您仍然会收到相同的错误(虽然不是警告)。即使在 C++98 代码中你也会收到警告,因为现代 g++ 编译器 (>=4.9) 将大括号解释为std::initializer_list(即使你不使用-std=c++11编译)他们认为这是一个扩展,并且默认情况下启用(请参阅警告消息)。 -
@vsoftco:你当然是对的——我应该先仔细看看代码。但如果可能的话,我仍然会推荐使用 c++11 标志。
标签: c++ arrays initializer-list