我正在尝试使用升压累加器来计算滚动平均值。当我像这样声明变量内联时:
#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
using namespace boost::accumulators;
int main()
{
// Define rolling_mean accumulator
accumulator_set<double, stats<tag::rolling_mean > > acc(tag::rolling_window::window_size = 5);
// push in some data ...
acc(1.2);
acc(2.3);
acc(3.4);
acc(4.5);
// Display the results ...
std::cout << "Mean: " << rolling_mean(acc) << std::endl;
return 0;
}
它工作得很好。当我将累加器声明为这样的类的成员时:
#include <iostream>
#include <boost/accumulators/accumulators.hpp>
#include <boost/accumulators/statistics/stats.hpp>
#include <boost/accumulators/statistics/rolling_mean.hpp>
using namespace boost::accumulators;
class DoMean {
private:
accumulator_set<double, stats<tag::rolling_mean > > m_acc(tag::rolling_window::window_size = 5);
public:
void addData(double val) {
this->m_acc(val);
}
double getMean(void) {
return rolling_mean(this->m_acc);
}
};
int main()
{
// Define an accumulator set for calculating the mean and the
// 2nd moment ...
DoMean meaner;
meaner.addData(1.2);
meaner.addData(2.3);
meaner.addData(3.4);
meaner.addData(4.5);
// push in some data ...
// Display the results ...
std::cout << "Mean: " << meaner.getMean() << std::endl;
return 0;
}
它失败了,给出了编译器错误:
accumulators::tag::rolling_window::window_size is not a type
...blah blah, many type template errors etc.