我有一个不可移动和不可复制的类型:
struct A
{
A(std::string p1, int p2){}
A(A const &) = delete;
A(A&&) = delete;
A& operator=(A const &) = delete;
A& operator=(A&) = delete;
};
我可以通过这种方式构建可选的 boost:
boost::optional<A> op(boost::in_place("abc", 5));
我还需要初始化boost::optional<A>
哪个是类成员。这是我的解决方案:
class B
{
public:
B(const boost::optional<A>& op): op_(op) {}
private:
const boost::optional<A>& op_;
};
B b(boost::optional<A>(boost::in_place("abc", 5)));
是否有可能只有boost::optional<A>
类成员并以某种方式初始化它?
编辑(澄清)
我想要boost::optional<A> op_
类数据成员,但我不知道如何初始化它。