原因:scoped_ptr的赋值操作符和拷贝构造函数被声明为了provate,所以它不能被赋值。
boost中scoped_ptr的部分代码:
private:
T * px;
scoped_ptr(scoped_ptr const &);
scoped_ptr & operator=(scoped_ptr const &);
typedef scoped_ptr<T> this_type;
void operator==( scoped_ptr const& ) const;
void operator!=( scoped_ptr const& ) const;
public:
typedef T element_type;
explicit scoped_ptr( T * p = 0 ): px( p ) // never throws
{
#if defined(BOOST_SP_ENABLE_DEBUG_HOOKS)
boost::sp_scalar_constructor_hook( px );
#endif
}
class MyClass{
public:
MyClass();
private:
scoped_ptr<int> m_pScopedPtr;
}
MyClass::MyClass()
:m_pScopedPtr(new int(100))//这样就可以了
{
}