当前位置:网站首页>Smart pointer shared_ PTR and weak_ Difference of PTR

Smart pointer shared_ PTR and weak_ Difference of PTR

2022-07-05 03:26:00 Alex1_ Code

weak_ptr To solve the problem shared_ptr The problem of circular quotation , Prevent bidirectional binding

1. share_ptr Example

 Insert picture description here
 Insert picture description here

Schematic diagram

 Insert picture description here
It can be seen that , When ptr_a,ptr_b Release , Did not lead to A,B The construction of class .

2. Right up there Example improvements :

 Insert picture description here
 Insert picture description here

Schematic diagram

 Insert picture description here
At this time, both class objects are destructed , meanwhile ptr_a Of use_count by 2,ptr_b Of use_count by 1

原网站

版权声明
本文为[Alex1_ Code]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/02/202202140745513518.html