计算Boost库中的平均值和时刻

时间:2010-08-20 19:44:09

标签: boost

我正在尝试使用Boost库的accumulator来实现一个计算平均值和时刻的程序。这是代码:

#include <iostream>

#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/mean.hpp>
#include <boost/accumulators/statistics/moment.hpp>
using namespace  boost::accumulators;

int main()
{
    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);
    std::cout<<"Mean  :  "<<mean(acc)<<std::endl;
    std::cout<<"moment : "<<accumulators::moment<2>(acc)<<std::endl;

    return 0;
}

但我得到一个很长的错误列表(如下所列)。我尝试boost::accumulator而不是累加器,因为在我使用累加器程序的行中它向我显示一条红线,在使用boost::accumulator后,红线被隐藏但错误是相同的。 我该如何解决这个问题?

1>------ Build started: Project: examples, Configuration: Debug Win32 ------
1>Build started 8/20/2010 11:41:31 PM.
1>InitializeBuildStatus:
1>  Touching "Debug\examples.unsuccessfulbuild".
1>ClCompile:
1>  examples.cpp
1>  using native typeof
1>c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(36): error C2027: use of undefined type 'boost::fusion::void_'
1>          c:\users\david\desktop\boost_1_44_0\boost\fusion\container\vector\vector_fwd.hpp(16) : see declaration of 'boost::fusion::void_'
1>          c:\users\david\desktop\boost_1_44_0\boost\mpl\eval_if.hpp(41) : see reference to class template instantiation 'boost::accumulators::detail::accumulator_set_result<AccumulatorSet,Feature>' being compiled
1>          with
1>          [
1>              AccumulatorSet=boost::accumulators::accumulator_set<double,boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>>,
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(57) : see reference to class template instantiation 'boost::mpl::eval_if<C,F1,F2>' being compiled
1>          with
1>          [
1>              C=boost::accumulators::detail::is_accumulator_set<boost::accumulators::accumulator_set<double,boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>>>,
1>              F1=boost::accumulators::detail::accumulator_set_result<boost::accumulators::accumulator_set<double,boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>>,boost::accumulators::tag::mean>,
1>              F2=boost::accumulators::detail::argument_pack_result<boost::accumulators::accumulator_set<double,boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>>,boost::accumulators::tag::mean>
1>          ]
1>          c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17) : see reference to class template instantiation 'boost::accumulators::detail::extractor_result<A,Feature>' being compiled
1>          with
1>          [
1>              A=boost::accumulators::accumulator_set<double,boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>>,
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(36): error C2146: syntax error : missing ';' before identifier 'type'
1>c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(36): error C4430: missing type specifier - int assumed. Note: C++ does not support default-int
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2893: Failed to specialize function template 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const Arg1 &) const'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          With the following template arguments:
1>          'boost::accumulators::accumulator_set<Sample,Features>'
1>          with
1>          [
1>              Sample=double,
1>              Features=boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A1 &) const' : expects 2 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(112) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &) const' : expects 3 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &) const' : expects 4 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &) const' : expects 5 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &) const' : expects 6 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &) const' : expects 7 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &) const' : expects 8 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &,const A7 &) const' : expects 9 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &,const A7 &,const A8 &) const' : expects 10 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &,const A7 &,const A8 &,const A9 &) const' : expects 11 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,const A0 &,const A1 &,const A2 &,const A3 &,const A4 &,const A5 &,const A6 &,const A7 &,const A8 &,const A9 &,const A10 &) const' : expects 12 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,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' : expects 13 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,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' : expects 14 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,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' : expects 15 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(17): error C2780: 'detail::extractor_result<Arg1,Feature>::type boost::accumulators::extractor<Feature>::operator ()(const AccumulatorSet &,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 &) const' : expects 16 arguments - 1 provided
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>          c:\users\david\desktop\boost_1_44_0\boost\accumulators\framework\extractor.hpp(148) : see declaration of 'boost::accumulators::extractor<Feature>::operator ()'
1>          with
1>          [
1>              Feature=boost::accumulators::tag::mean
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(18): error C2653: 'accumulators' : is not a class or namespace name
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(18): error C2679: binary '<<' : no operator found which takes a right-hand operand of type 'overloaded-function' (or there is no acceptable conversion)
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(679): could be 'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(726): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(764): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const char *)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(811): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,char)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(937): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const signed char *)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(944): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,signed char)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(951): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const unsigned char *)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(958): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,unsigned char)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(1085): or       'std::basic_ostream<_Elem,_Traits> &std::operator <<<char,std::char_traits<char>>(std::basic_ostream<_Elem,_Traits> &,const std::error_code &)' [found using argument-dependent lookup]
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(186): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ostream<_Elem,_Traits> &(__cdecl *)(std::basic_ostream<_Elem,_Traits> &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(192): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_ios<_Elem,_Traits> &(__cdecl *)(std::basic_ios<_Elem,_Traits> &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(199): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::ios_base &(__cdecl *)(std::ios_base &))'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(206): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::_Bool)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(226): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(short)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(260): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned short)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(280): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(int)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(305): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned int)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(325): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(345): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned long)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(366): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(__int64)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(386): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(unsigned __int64)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(407): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(float)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(427): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(double)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(447): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(long double)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(467): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(const void *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          c:\program files\microsoft visual studio 10.0\vc\include\ostream(487): or       'std::basic_ostream<_Elem,_Traits> &std::basic_ostream<_Elem,_Traits>::operator <<(std::basic_streambuf<_Elem,_Traits> *)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>          while trying to match the argument list '(std::basic_ostream<_Elem,_Traits>, overloaded-function)'
1>          with
1>          [
1>              _Elem=char,
1>              _Traits=std::char_traits<char>
1>          ]
1>c:\users\david\documents\visual studio 2010\projects\examples\examples\examples.cpp(18): error C2676: binary '<<' : 'boost::accumulators::accumulator_set<Sample,Features>' does not define this operator or a conversion to a type acceptable to the predefined operator
1>          with
1>          [
1>              Sample=double,
1>              Features=boost::accumulators::stats<boost::accumulators::tag::mean,boost::accumulators::tag::moment<2>>
1>          ]
1>
1>Build FAILED.
1>
1>Time Elapsed 00:00:07.38
========== Build: 0 succeeded, 1 failed, 0 up-to-date, 0 skipped ==========

2 个答案:

答案 0 :(得分:7)

您可能需要

#include <boost/accumulators/statistics/stats.hpp>

但是,在Mac OS X上构建相同的示例并收到以下错误:

**** Build of configuration Debug for project Accumulators ****

make all 
Building file: ../src/Accumulators.cpp
Invoking: GCC C++ Compiler
g++ -I/opt/local/include -O0 -g3 -Wall -c -fmessage-length=0 -MMD -MP -MF"src/Accumulators.d" -MT"src/Accumulators.d" -o"src/Accumulators.o" "../src/Accumulators.cpp"
../src/Accumulators.cpp: In function 'int main()':
../src/Accumulators.cpp:22: error: 'accumulators' has not been declared
../src/Accumulators.cpp:22: error: no match for 'operator<<' in 'acc << std::endl'
make: *** [src/Accumulators.o] Error 1

然后我将accumulators::moment<2>(acc)更改为moment<2>(acc),并且构建正常。代码如下所示:

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

答案 1 :(得分:2)

除了已包含的标题外,您还必须添加:

#include <boost/accumulators/statistics/moment.hpp>

然后,除了Accumulators命名空间之外,还要添加Boost命名空间:

using namespace boost;

然后编译:

g++ acc.cpp -o acc -I/usr/local/include/boost/ -L/usr/local/lib/