Checking boost shared pointer for null




















Both p1 and p2 are null, but they are empty too because they don't have any control block associated with them. On the other hand, p3 is null but not empty because it has a control block with a managed nullptr and a reference count of 1.

Simply speaking, a control block keeps a pointer to the managed object and a reference counter, among other bookkeeping data. That is achieved through the aliasing constructor.

Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science. Stack Gives Back Featured on Meta. New post summary designs on greatest hits now, everywhere else eventually. Linked Related Hot Network Questions. Will this return the right value? Null 1, 9 9 gold badges 26 26 silver badges 32 32 bronze badges. Yochai Timmer Yochai Timmer Add a comment. Active Oldest Votes. Use: if! Ralph Ralph 5, 1 1 gold badge 20 20 silver badges 18 18 bronze badges.

You can just test the pointer as a boolean: it will evaluate to true if it is non-null and false if it is null: if! MSalters MSalters k 8 8 gold badges silver badges bronze badges.

James Kanze James Kanze k 15 15 gold badges silver badges bronze badges. Jan Henke Jan Henke 1 1 gold badge 16 16 silver badges 27 27 bronze badges. Sign up or log in Sign up using Google. Sign up using Facebook. Sign up using Email and Password. Post as a guest Name. Email Required, but never shown. The Overflow Blog. Podcast Making Agile work for data science.



0コメント

  • 1000 / 1000