Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

weak_ptr<User_Class> is none pointer type

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?


1 Answers

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!
like image 145
Igor R. Avatar answered Jul 26 '26 07:07

Igor R.



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!