boost-smart-ptr

How can I take a single element out of a boost library (e.g. shared_pointer)?

我是研究僧i 提交于 2020-01-01 09:34:07
问题 I've been playing around with some Boost components, and the only one I see a direct need for in the project I'm working on is boost::shared_ptr . Would it be difficult to just include the required files for shared_ptr , or at least just include files for the Boost smart_ptr directory in my project? They seem to have some external dependencies on other parts of Boost - but I figure there's an easy way to just use certain components of the Boost library and I'm missing it. If you can tell me

intrusive_ptr: Why isn't a common base class provided?

廉价感情. 提交于 2019-12-10 03:15:07
问题 boost::intrusive_ptr requires intrusive_ptr_add_ref and intrusive_ptr_release to be defined. Why isn't a base class provided which will do this? There is an example here: http://lists.boost.org/Archives/boost/2004/06/66957.php, but the poster says "I don't necessarily think this is a good idea". Why not? Update: I don't think the fact that this class could be misused with Multiple Inheritance is reason enough. Any class which derives from multiple base classes with their own reference count

Disable exception working for boost::smart_ptr but not for boost::property_tree

江枫思渺然 提交于 2019-12-06 13:50:16
问题 I'm using boost 1.57. I need to disable exception support in my not widely-used proprietary compiler. When I needed to use boost::smart_ptr , the following steps worked like a charm: Disabled C++11 support using the following user.hpp file (compiling with -DBOOST_USER_CONFIG="<user.hpp>" ): #define BOOST_HAS_NRVO #define BOOST_NO_COMPLETE_VALUE_INITIALIZATION #define BOOST_NO_CXX11_AUTO_DECLARATIONS #define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS #define BOOST_NO_CXX11_CHAR16_T #define BOOST_NO

intrusive_ptr: Why isn't a common base class provided?

天涯浪子 提交于 2019-12-05 03:01:00
boost::intrusive_ptr requires intrusive_ptr_add_ref and intrusive_ptr_release to be defined. Why isn't a base class provided which will do this? There is an example here: http://lists.boost.org/Archives/boost/2004/06/66957.php , but the poster says "I don't necessarily think this is a good idea". Why not? Update: I don't think the fact that this class could be misused with Multiple Inheritance is reason enough. Any class which derives from multiple base classes with their own reference count would have the same issue. Whether these refcounts are implemented via a base class or not makes no

Disable exception working for boost::smart_ptr but not for boost::property_tree

时光总嘲笑我的痴心妄想 提交于 2019-12-04 19:57:54
I'm using boost 1.57. I need to disable exception support in my not widely-used proprietary compiler. When I needed to use boost::smart_ptr , the following steps worked like a charm: Disabled C++11 support using the following user.hpp file (compiling with -DBOOST_USER_CONFIG="<user.hpp>" ): #define BOOST_HAS_NRVO #define BOOST_NO_COMPLETE_VALUE_INITIALIZATION #define BOOST_NO_CXX11_AUTO_DECLARATIONS #define BOOST_NO_CXX11_AUTO_MULTIDECLARATIONS #define BOOST_NO_CXX11_CHAR16_T #define BOOST_NO_CXX11_CHAR32_T #define BOOST_NO_CXX11_CONSTEXPR #define BOOST_NO_CXX11_DECLTYPE #define BOOST_NO_CXX11

How can I take a single element out of a boost library (e.g. shared_pointer)?

≯℡__Kan透↙ 提交于 2019-12-04 04:11:04
I've been playing around with some Boost components, and the only one I see a direct need for in the project I'm working on is boost::shared_ptr . Would it be difficult to just include the required files for shared_ptr , or at least just include files for the Boost smart_ptr directory in my project? They seem to have some external dependencies on other parts of Boost - but I figure there's an easy way to just use certain components of the Boost library and I'm missing it. If you can tell me what parts I need or point me to a good tutorial I'd be most grateful! Praetorian You can use the bcp

Explicitly deleting a shared_ptr

主宰稳场 提交于 2019-12-03 06:47:48
问题 Simple question here: are you allowed to explicitly delete a boost::shared_ptr yourself? Should you ever? Clarifying, I don't mean delete the pointer held by the shared_ptr . I meant the actual shared_ptr itself. I know most people suggest to not do it, so I was just wondering if it's OK to explicitly do it. 回答1: Your question isn't clear. If you've allocated a shared_ptr dynamically then you're certainly allowed to delete it whenever you want. But if you're asking whether you're allowed to

Can boost::smart_ptr be used in polymorphism?

谁说胖子不能爱 提交于 2019-11-30 13:48:43
Can boost::smart_ptr such as scoped_ptr and shared_ptr be used in polymorphism? class SomeClass { public: SomeClass() { a_ptr.reset(new SubClass); } private: boost::scoped_ptr<SuperClass> a_ptr; } Yes: #include <string> #include <iostream> using namespace std; #include <boost\shared_ptr.hpp> using namespace boost; class Foo { public: virtual string speak() const { return "Foo"; } virtual ~Foo() {}; }; class Bar : public Foo { public: string speak() const { return "Bar"; } }; int main() { boost::shared_ptr<Foo> my_foo(new Bar); cout << my_foo->speak(); } Output is: Bar I believe the answer is

How to use boost::smart_ptr in polymorphism?

折月煮酒 提交于 2019-11-30 09:59:40
Boost smart pointers can be used with polymorphism , but how do you cast the subclass back to the pointer? using namespace boost; // ... shared_ptr<SuperClass> a_ptr(new SubClass); // ... shared_ptr<SubClass> b_ptr = (shared_ptr<SubClass>)a_ptr; // Doesn't compile The last line doesn't compile and gives error C2440: 'type cast' : cannot convert from 'boost::shared_ptr <T> ' to 'boost::shared_ptr <T> ' You need to use static_pointer_cast : struct B { virtual ~B() { } }; struct D : B { }; shared_ptr<B> bp(new D); shared_ptr<D> dp(static_pointer_cast<D>(b)); (There are also dynamic_pointer_cast

Can boost::smart_ptr be used in polymorphism?

99封情书 提交于 2019-11-29 19:37:57
问题 Can boost::smart_ptr such as scoped_ptr and shared_ptr be used in polymorphism? class SomeClass { public: SomeClass() { a_ptr.reset(new SubClass); } private: boost::scoped_ptr<SuperClass> a_ptr; } 回答1: Yes: #include <string> #include <iostream> using namespace std; #include <boost\shared_ptr.hpp> using namespace boost; class Foo { public: virtual string speak() const { return "Foo"; } virtual ~Foo() {}; }; class Bar : public Foo { public: string speak() const { return "Bar"; } }; int main() {