Error while copy constructing boost::shared_ptr using C++11

我与影子孤独终老i 提交于 2019-12-04 13:44:47

This is a known bug in Boost. The older versions (1.48 and lower) of Boost are not compilable under C++11, at least, not all. Personally, I use this workaround:

#ifdef MY_LIB_COMPILING_UNDER_CXX11

#include <memory>

namespace my_lib {

using std::shared_ptr;
using std::weak_ptr;

};

#else

#include <boost/shared_ptr.hpp>
#include <boost/weak_ptr.hpp>

namespace my_lib {

using boost::shared_ptr;
using boost::weak_ptr;

};

#endif

Where MY_LIB_COMPILING_UNDER_CXX11 would be a flag that you set either passed to the compiler or deriving it from the compiler's C++11 flags. And, then, in the rest of the library I only use my_lib::shared_ptr. This works very well.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!