[Accumulators] Errors compiling the "Hello, World!" example
Hello! I'm new to Accumulators. I've tried to compile the "Hello, World!" example (found in the User Guide) but it fails: --- [error] --- $ g++ -ansi -Wall -o accumulators_test1 accumulators_test1.cpp /usr/include//boost/accumulators/statistics_fwd.hpp: In function ‘int main()’: /usr/include//boost/accumulators/statistics_fwd.hpp:87: error: ‘template<int N> struct boost::accumulators::tag::moment’ is not a function, /usr/include//boost/accumulators/statistics/moment.hpp:104: error: conflict with ‘template<int T2, class Arg1, class A0, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14> typename boost::accumulators::detail::extractor_result<Arg1, boost::accumulators::tag::moment<T2> >::type boost::accumulators::extract::moment(const Arg1&, const A0&, const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const A14&)’ accumulators_test1.cpp:22: error: in call to ‘moment’ --- [/error] --- My system is: Fedora 12 x86_64 -- GCC 4.4.2 20091222 (Red Hat 4.4.2-20) -- Boost 1.39 (also tried with the latest Boost trunk) Just for the sake of completeness, here below is the code stored in the "accumulators_test1.cpp" file --- [code] --- #include <iostream> #include <boost/accumulators/accumulators.hpp> #include <boost/accumulators/statistics/stats.hpp> #include <boost/accumulators/statistics/mean.hpp> #include <boost/accumulators/statistics/moment.hpp> using namespace boost::accumulators; int main() { // Define an accumulator set for calculating the mean and the // 2nd moment ... accumulator_set<double, stats<tag::mean, tag::moment<2> > > acc; // push in some data ... acc(1.2); acc(2.3); acc(3.4); acc(4.5); // Display the results ... std::cout << "Mean: " << mean(acc) << std::endl; std::cout << "Moment: " << moment<2>(acc) << std::endl; return 0; } --- [/code] --- Where I am wrong? Thank you very much for any help!! Best, -- Marco
On 1/11/2010 10:05 AM, Marco Guazzone wrote:
Hello!
I'm new to Accumulators. I've tried to compile the "Hello, World!" example (found in the User Guide) but it fails:
--- [error] --- $ g++ -ansi -Wall -o accumulators_test1 accumulators_test1.cpp
/usr/include//boost/accumulators/statistics_fwd.hpp: In function ‘int main()’: /usr/include//boost/accumulators/statistics_fwd.hpp:87: error: ‘template<int N> struct boost::accumulators::tag::moment’ is not a function, /usr/include//boost/accumulators/statistics/moment.hpp:104: error: conflict with ‘template<int T2, class Arg1, class A0, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14> typename boost::accumulators::detail::extractor_result<Arg1, boost::accumulators::tag::moment<T2> >::type boost::accumulators::extract::moment(const Arg1&, const A0&, const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const A14&)’ accumulators_test1.cpp:22: error: in call to ‘moment’ --- [/error] ---
<snip>
Where I am wrong?
Marco, You are not wrong. With my hello world example, I have inadvertently led you into the murky waters of C++ name look-up. GCC does it one way, the rest of the world does it another, and you are caught in the fray. If you qualify the call to moment (accumulators::moment<2>(acc)), the problem will go away. I'll fix the docs for 1.42 and see if there's something can be done in the library to obviate the need for qualification in the future. Sorry for the trouble, -- Eric Niebler BoostPro Computing http://www.boostpro.com
On Mon, Jan 11, 2010 at 11:37 AM, Eric Niebler <eric@boostpro.com> wrote:
On 1/11/2010 10:05 AM, Marco Guazzone wrote:
Hello!
I'm new to Accumulators. I've tried to compile the "Hello, World!" example (found in the User Guide) but it fails:
--- [error] --- $ g++ -ansi -Wall -o accumulators_test1 accumulators_test1.cpp
/usr/include//boost/accumulators/statistics_fwd.hpp: In function ‘int main()’: /usr/include//boost/accumulators/statistics_fwd.hpp:87: error: ‘template<int N> struct boost::accumulators::tag::moment’ is not a function, /usr/include//boost/accumulators/statistics/moment.hpp:104: error: conflict with ‘template<int T2, class Arg1, class A0, class A1, class A2, class A3, class A4, class A5, class A6, class A7, class A8, class A9, class A10, class A11, class A12, class A13, class A14> typename boost::accumulators::detail::extractor_result<Arg1, boost::accumulators::tag::moment<T2> >::type boost::accumulators::extract::moment(const Arg1&, const A0&, const A1&, const A2&, const A3&, const A4&, const A5&, const A6&, const A7&, const A8&, const A9&, const A10&, const A11&, const A12&, const A13&, const A14&)’ accumulators_test1.cpp:22: error: in call to ‘moment’ --- [/error] ---
<snip>
Where I am wrong?
Marco,
You are not wrong. With my hello world example, I have inadvertently led you into the murky waters of C++ name look-up. GCC does it one way, the rest of the world does it another, and you are caught in the fray. If you qualify the call to moment (accumulators::moment<2>(acc)), the problem will go away.
Thank you Eric! Just for info, in my case, to fix the problem, I had to use fully qualification: boost::accumulators::moment<2>(acc) instead of accumulators::moment<2>(acc)
I'll fix the docs for 1.42 and see if there's something can be done in the library to obviate the need for qualification in the future.
Sorry for the trouble,
No problem :) Best, -- Marco
On 1/11/2010 10:45 PM, Marco Guazzone wrote:
Just for info, in my case, to fix the problem, I had to use fully qualification:
boost::accumulators::moment<2>(acc)
instead of
accumulators::moment<2>(acc)
Correct. You can make this easier with a namespace alias: namespace ba = boost::accumulators; ... ba::moment<2>(acc); HTH, -- Eric Niebler BoostPro Computing http://www.boostpro.com
participants (2)
-
Eric Niebler
-
Marco Guazzone