如何初始化valarray的std共享指针

时间:2016-05-12 17:30:25

标签: c++ shared-ptr smart-pointers

我正在尝试初始化std::valarray<double>的共享指针,我的代码是

class foo {

    public:

        foo();

    private:

        std::shared_ptr<std::valarray<double>> meanValues;
};

在构造函数中,我想填写meanValues

foo::foo() {

    this->meanValues = std::make_shared<std::valarray<double>>(2);
}

如何填充meanValues以获得两个值{1.2, 4.5}

1 个答案:

答案 0 :(得分:4)

您可以明确指定std::initializer_list

foo::foo()
{
    this->meanValues = std::make_shared<std::valarray<double>>(std::initializer_list<double>{1.2, 4.5});
}