I used ordinary pointers in my project. I had some problems with memory and changed ordinary pointers for weak_ptr. I had error:
error: base operand of ‘->’ has non-pointer type ‘boost::weak_ptr’
Why? What should I do?
First, lock the weak_ptr - if it's not expired, you'll get the appropriate shared_ptr:
shared_ptr<my_type> p = weak.lock();
if (p)
p->do_something();
else
// expired!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With