考虑与不能直接存储的成员,例如一类,因为它不会有一个默认的构造函数,封装类的构造函数没有足够的信息来创建它: class Foo
{
public:
Foo(){} // Default ctor
private:
/* Won't build: no default ctor or way to call it's
non-default ctor at F
指定结构的可选成员的最佳风格是什么? 比如我有一个结构: struct B{
public:
int x;
}
struct A{
public:
boost::optional<B> b;
};
void foo(){
A a;
a.b.x = 10; //Runtime exception because a.b is not ini