boost::scoped_ptr是一个简单的智能指针,它可以保证在离开作用域后对象被自己主动释放。 boost::scoped_ptr的实现是利用了一个栈上的对象去管理一个堆上的对象。从而使得堆上的对象随着栈上的对象销毁时自己主动删除。 boost::scoped_ptr 特点 不能转换全部权 scoped_ptr所管理的对象生命周期只局限于一个区间(该...
#ifndef BOOST_NO_AUTO_PTRexplicitscoped_ptr( std::auto_ptr<T>p ) BOOST_NOEXCEPT : px( p.release() ){#ifdefined(BOOST_SP_ENABLE_DEBUG_HOOKS)boost::sp_scalar_constructor_hook( px );#endif}#endif~scoped_ptr()//never throws {#ifdefined(BOOST_SP_ENABLE_DEBUG_HOOKS)boost::sp_scalar_des...
shared_ptr( shared_ptr<Y> const & r, typename boost::detail::sp_enable_if_convertible<Y,T>::type = boost::detail::sp_empty() ) #else shared_ptr( shared_ptr<Y> const & r ) #endif BOOST_NOEXCEPT : px( r.px ), pn( r.pn ) { boost::detail::sp_assert_convertible< Y, T >...
shared_ptr<T>:px代表指向具体对象的指针;pn保存引用计数相关信息。shared_ptr的核心就是shared_count,因为整个shared_ptr实现都没有出现对引用计数的具体操作,比如+1 -1等。而每一次需要用到对引用计数的操作都调用了shared_count内部封装的函数,比如:swap、==、get_deleter、use_count等。 shared_count:内部包含...
shared_ptr是一个最像指针的“智能指针”,它是boost.smart_ptr库中最有价值、最重要的组成部分,Boost库的许多组件(甚至还包括一些其他领域的智能指针)都使用了shared_ptr,所以它被毫无悬念地收入C++11标准。 shared_ptr与scoped_ptr一样包装了new操作符在堆上分配的动态对象,但它实现的是引用计数型的智能指针,可以...
1)构造函数,可以通过一般指针,std::auto_ptr,boost::shared_ptr,boost::weak_ptr来构造,还可以构造的时候指定如果delete指针(redwolf注:用户自己提供析构器,智能指针在删除时不调用默认的析构器(deleter)。析构器并不是析构函数。)。 2)拷贝构造函数 ...
#include <boost/log/common.hpp> #include <boost/log/sinks.hpp> #include <boost/log/sources/severity_logger.hpp> #include <boost/utility/empty_deleter.hpp> #include <boost/shared_ptr.hpp> #include <iostream> using namespace boost::log; bool only_warnings(const attribute_value_set &set) {...
问boost或C++0x中的任何RAII模板ENshared_ptr提供了指定custom deleter的可能性。当需要销毁指针时,删除...
Here is the new code which is usingscope_ptr: // timer.h #include<boost/smart_ptr/scoped_ptr.hpp>class Timer { public: explicit Timer(double); ~Timer(); private: class Implementation;//Implementation *pImpl;boost::scoped_ptr<Implementation> pImpl;}; ...
rdbuf())); //输出到console上与上面等价 boost::shared_ptr<std::ostream> stream_ptr(&std::clog, boost::null_deleter()); sink->locked_backend()->add_stream(stream_ptr); logging::core::get()->add_sink(sink); } 这种方式, 和方式1中效果完全一样; 这里简要介绍一下sink, 后续有详细的...