Search code examples
c++boostboost-accumulators

boost accumulators example doesn't compile


I installed boost (1.60.0) on Linux Mint 17.3 Rosa and tried to compile the boost accumulator example (http://www.boost.org/doc/libs/1_60_0/doc/html/accumulators/user_s_guide.html) with the gcc compiler (v 4.8.4 64 bit) using this command:

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

Compilation failed with a long list of error messages starting with:

>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;

After looking up accumulators.hpp I changed accumulators::moment<2> to moment<2>. This did the trick and the compilation (with the same flags) succeeded. Alternatively, prefixing "accumulators" with "boost::accumulators::moment<2>" worked too. So my question is: Is there something wrong with my installation of boost or is there a typo in the example from the tutorial ?


Solution

  • This seems to be a typo indeed.

    You can use the whole boost namespace (bad idea) to make the example compile:

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

    Or, like you already did, just remove the accumulators:: specificier and only use namespace boost::accumulators;.

    Or just specify it's fully qualified name : boost::accumulators::moment<2>(acc).