gpt4 book ai didi

c++ - boost 累加器示例不编译

转载 作者:太空宇宙 更新时间:2023-11-04 13:15:12 25 4
gpt4 key购买 nike

我在 Linux Mint 17.3 Rosa 上安装了 boost (1.60.0),并尝试使用以下命令使用 gcc 编译器(v 4.8.4 64 位)编译 boost 累加器示例 (http://www.boost.org/doc/libs/1_60_0/doc/html/accumulators/user_s_guide.html):

>g++ -o exaccu exaccumulator.cpp -I/usr/local/lib/boost_1_60_0/

编译失败,出现一长串错误消息,开头为:

>exaccumulator.cpp: In function ‘int main()’:
>exaccumulator.cpp:22:32: error: ‘accumulators’ has not been declared
>std::cout << "Moment: " << accumulators::moment<2>(acc) << std::endl;

在查找 accumulators.hpp 之后,我将 accumulators::moment<2> 更改为 moment<2>。这成功了,编译(使用相同的标志)成功了。或者,在“accumulators”前面加上“boost::accumulators::moment<2>”也可以。所以我的问题是:我安装的 boost 有问题还是教程中的示例有错字?

最佳答案

这似乎确实是一个错字。

您可以使用整个 boost使示例编译的命名空间(坏主意):

using namespace boost;
accumulators::moment<2>(acc);

或者,就像您已经做的那样,只需删除 accumulators::更具体,只使用 namespace boost::accumulators; .

或者只指定它的完全限定名称:boost::accumulators::moment<2>(acc) .

关于c++ - boost 累加器示例不编译,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37731872/

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