How to set weak pointer as nullptr | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

How to set weak pointer as nullptr

Hi Refer code below : I set member variable weak pointer of class for catA and catB. As soon as catB died, I just need to do reset on catB and weak pointer of catA is expired... Now catA is friend with catC... This time catC scope is not over so can't use reset but just want to unfriend .... Thought to do nullptr assignment to weak pointer inside unfriend method but it doesn't compile.. How to assign nullptr to weak pointer or is there a better alternative approach ? Feel free to ask for queries if any... I will appreciate your feedback to improve the implementation. https://code.sololearn.com/crLusXibyk4t/?ref=app

29th Jan 2022, 9:33 PM
Ketan Lalcheta
Ketan Lalcheta - avatar
2 Answers
+ 2
You can still use frnd.reset() - it will just detach the weak pointer, leaving the catC alive.
30th Jan 2022, 11:18 AM
Volodymyr Chelnokov
Volodymyr Chelnokov - avatar
0
Thank you 😊
30th Jan 2022, 11:24 AM
Ketan Lalcheta
Ketan Lalcheta - avatar