首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何在类成员初始化中使用boost累加器quantile_probability?

如何在类成员初始化中使用boost累加器quantile_probability?
EN

Stack Overflow用户
提问于 2022-09-15 21:04:23
回答 1查看 29关注 0票数 1

Boost累加器有一个不幸的怪癖,当在类内部使用时,api接口的行为会有所不同。

我试图在类中使用Boost累加器quantile_probability,但是我想不出如何使它工作。

这个问题类似于这个问题:Can boost accumulators be used as class members

代码语言:javascript
复制
  #include <boost/accumulators/accumulators.hpp>
  #include <boost/accumulators/statistics/stats.hpp>
  #include <boost/accumulators/statistics/weighted_p_square_cumul_dist.hpp>
  #include <boost/accumulators/statistics/weighted_p_square_quantile.hpp>
  #include <boost/accumulators/statistics/parameters/quantile_probability.hpp>

  namespace ba = boost::accumulators;

  typedef ba::accumulator_set<int64_t, ba::stats<ba::tag::weighted_p_square_quantile>, int64_t> accumulator_t;

  struct Foo {
      accumulator_t myAcc(ba::quantile_probability = 0.90);  // Doesn't work. ERROR: ‘ba::quantile_probability’ is not a type
  };

  accumulator_t acc(ba::quantile_probability = 0.90);   // I just fine!
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-09-16 00:03:20

accumulator_t myAcc(中的方括号被解析为成员函数,在这种情况下,这是定义一个变量为ba::qunatile_probability的函数。但那不是一种类型,所以它失败了。

您需要用={编写初始化程序,或者将其写入构造函数的初始化程序列表中。

代码语言:javascript
复制
struct Foo {
    // One of these
    accumulator_t myAcc = accumulator_t(ba::quantile_probability = 0.90);

    accumulator_t myAcc{ba::quantile_probability = 0.90};
    
    accumulator_t myAcc;
    Foo() : myAcc(ba::quantile_probability = 0.90) {}
};
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/73737420

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档