shared-ptr

Difference between QSharedPointer::isNull() and operator!()

醉酒当歌 提交于 2020-02-03 16:27:42
问题 in Qt docs we read: bool QSharedPointer::operator! () const Returns true if this object is null. This function is suitable for use in if-constructs, like: if (!sharedptr) { ... } and bool QSharedPointer::isNull () const Returns true if this object is holding a reference to a null pointer. What is the difference between these two functions? This is clear what is reference to a null pointer, but what means here "if the object is null" ? What determines if QSharedPointer is null ? How do these

Difference between QSharedPointer::isNull() and operator!()

梦想与她 提交于 2020-02-03 16:25:07
问题 in Qt docs we read: bool QSharedPointer::operator! () const Returns true if this object is null. This function is suitable for use in if-constructs, like: if (!sharedptr) { ... } and bool QSharedPointer::isNull () const Returns true if this object is holding a reference to a null pointer. What is the difference between these two functions? This is clear what is reference to a null pointer, but what means here "if the object is null" ? What determines if QSharedPointer is null ? How do these

boost::shared_ptr and Return Type Resolver idiom

冷暖自知 提交于 2020-01-24 17:07:27
问题 I am currently working on a concept of Object known in Java or C# for C++. It would be similar to variant type like boost::any, however having wider functionality. For that purpose I am using boost::shared_ptr to internaly store actual data and I wanted to provide Return Type Resolver idiom for easily obtaining this data, as it is stored in actual implementation. I know I could use boost::shared_ptr automatic conversion during assigment operator or constructor but as I said shared_ptr is not

How do I pass protobuf's boost::shared_ptr pointer to function?

邮差的信 提交于 2020-01-24 17:07:10
问题 I have to pass a boost::shared_ptr : boost::shared_ptr<Protobuf::Person::Profile> pProfile = boost::make_shared<Protobuf::Person::Profile>(); which is protobuf's pointer, to a protobuf's function oPerson.set_allocated_profile(pProfile) but oPerson.set_allocated() expects a pointer to Protobuf::Person::Profile . I have tried couple of ways but I think when I try to convert protobuf object to JSON using pbjson::pb2Json which is a library function built on rapid json, the pointer goes out of

How do I pass protobuf's boost::shared_ptr pointer to function?

馋奶兔 提交于 2020-01-24 17:06:26
问题 I have to pass a boost::shared_ptr : boost::shared_ptr<Protobuf::Person::Profile> pProfile = boost::make_shared<Protobuf::Person::Profile>(); which is protobuf's pointer, to a protobuf's function oPerson.set_allocated_profile(pProfile) but oPerson.set_allocated() expects a pointer to Protobuf::Person::Profile . I have tried couple of ways but I think when I try to convert protobuf object to JSON using pbjson::pb2Json which is a library function built on rapid json, the pointer goes out of

c++11 std::shared_ptr + boost::serialization [duplicate]

≯℡__Kan透↙ 提交于 2020-01-22 11:19:51
问题 This question already has answers here : How can boost::serialization be used with std::shared_ptr from C++11? (7 answers) boost serialize and std::shared_ptr (2 answers) Closed 6 years ago . Hi has anybody already managed to serialize a C++11 std::shared_ptr with boost::serialization. There are lots of obsolete posts out there but none with an acceptable solution. I am not going into discussion why I want to use the std::shared_ptr just accept it! I found this other post: boost serialize and

c++11 std::shared_ptr + boost::serialization [duplicate]

六月ゝ 毕业季﹏ 提交于 2020-01-22 11:17:12
问题 This question already has answers here : How can boost::serialization be used with std::shared_ptr from C++11? (7 answers) boost serialize and std::shared_ptr (2 answers) Closed 6 years ago . Hi has anybody already managed to serialize a C++11 std::shared_ptr with boost::serialization. There are lots of obsolete posts out there but none with an acceptable solution. I am not going into discussion why I want to use the std::shared_ptr just accept it! I found this other post: boost serialize and

C++ 11: smart pointers usage [duplicate]

≡放荡痞女 提交于 2020-01-22 03:46:15
问题 This question already has answers here : Which kind of pointer do I use when? (4 answers) Closed 5 years ago . What are the best practices for using smart. Are there situations in which i should prefer using raw pointer instead of smart pointers? For example, if i know that class A creates class B and is the only owner of B - if there a reason to use smart pointers? If you know of any good articles on that subject, please share. 回答1: If the pointer owns the object at any time, then use a

How to pass shared_ptr to class with lower lifetime?

别来无恙 提交于 2020-01-21 08:49:25
问题 I'd like to optimize my code. I have one class that have shared_ptr data member. In some method of this class I create objects that need use this member (just to get information from object pointed by shared_ptr). I know that lifetime of these created objects is lower than my main class. How to pass this pointer? I think another shared_ptrs are unnecessary (because I have warranty that object will exist). So what should get my created classes? Should they get raw pointer? Weak_ptr? Or the

Why does it look like boost::shared_ptr constructions are getting slower?

时光毁灭记忆、已成空白 提交于 2020-01-17 03:04:37
问题 I have a problem with boost shared_ptr. The initialization time of the smart pointer in the cycle is increased after the first iteration. The first iteration takes 40 msec. Every other iteration takes about 400 msec. I have no idea why it happens. I checked and there are no memory leaks and all destructors are called. Does anyone have a solution of this case? PS. However, when I use the boost::ptr_vector, the time is not increased( but only in debug version :) ). See example: class A; typedef