Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
boost::scoped_ptr可以在类的构造函数中初始化类型的类成员吗?如何? (不在初始化列表中)
boost::scoped_ptr
是的。您可以使用 reset() 成员函数。
class foo { public: foo() { p.reset(new bar()); } private: boost::scoped_ptr<bar> p; };
scoped_ptr 有一个方法scoped_ptr<T>::reset(T * p=0),您可以在封闭类的构造函数中调用该方法。
scoped_ptr<T>::reset(T * p=0)