为什么wp5
不指向值为Integer
的{{1}}?
50
是否可以创建使用#include <memory>
#include <iostream>
#include "DoubleLinkedList.h"
class Integer {
private:
int number;
public:
Integer(int number) : number(number) {}
int get() { return number; }
};
int main() {
Integer i1(10);
Integer i2(20);
i1 = i2;
std::cout << "i1 = " << i1.get() << std::endl;
Integer* i3 = new Integer(30);
std::shared_ptr<Integer> sp3 = std::make_shared<Integer>(i1);
std::shared_ptr<Integer> sp4 = std::shared_ptr<Integer>(new Integer(40));
std::weak_ptr<Integer> wp5 = std::shared_ptr<Integer>(new Integer(50));
std::weak_ptr<Integer> wp6 = sp4;
return 0;
}
作为指向shared_pointer<Integer>
的基本指针的weak_pointer<Integer>
或*i3
?