gpt4 book ai didi

c++ - Armadillo 初始值设定项列表不起作用

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:14:16 32 4
gpt4 key购买 nike

我在 Windows 10 下使用 MSVC2013 64 位编译器。

根据:

std::cout << arma::arma_version::as_string() << std::endl;

我有 Armadillio 库的 6.100.1 版(午夜蓝)。

例如,我启用了 C++11

auto il = { 10, 20, 30 };
for(auto ele : il)
cout<<ele<<endl;

正在工作。库也被正确添加,如下代码运行:

vec v;
v<<10<<20<<30;
cout<<v;

但是尝试使用 Armadillio 的初始化列表失败了。

vec v = { 1.0, 2.0, 3.0 };

导致编译错误:

错误:C2440:“初始化”:无法从“初始化列表”转换为“arma::Col”没有构造函数可以采用源类型,或者构造函数重载解析不明确

最佳答案

在文件夹 armadillo-6.100.1\include\armadillo_bits有一个名为 config.hpp 的配置文件。

你会发现一段话:

#if !defined(ARMA_USE_CXX11)
// #define ARMA_USE_CXX11
//// Uncomment the above line to forcefully enable use of C++11 features (eg. initialiser lists).
//// Note that ARMA_USE_CXX11 is automatically enabled when a C++11 compiler is detected.
#endif

所以看起来 MSVC2013 64 位没有被检测为 Armadillio 的 C++11 编译器。所以取消注释行

// #define ARMA_USE_CXX11

解决了我的问题。现在这就像魅力一样工作:

vec v = { 1.0, 2.0, 3.0 };
cout<<v;

关于c++ - Armadillo 初始值设定项列表不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33366730/

32 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com