C++11 用wake

tech2022-08-30  108

#include<iostream> using namespace std; /*     问题1:为什么会存在强弱指针的计数     问题2:强弱指针计数的用途是什么,具体的代码实现是什么。 */ int main() {     std::shared_ptr<int> ptr(new int(5));     std::shared_ptr<int>ptr2 = ptr;     std::weak_ptr<int>  ptr3 = ptr;     if (!ptr3.expired()) {//这个弱指针是否与对应的强指针有关联,并且强指针事存在的         std::shared_ptr<int> ptr4 = ptr3.lock();//通过弱指针的提升把它变为强指针,+     } }

最新回复(0)