#include<iostream> using namespace std; // private class for use by HasPtr only class U_Ptr { /** *因为在这个例子中所有的复制都是复制的“变量的常引用”,所以将U_Ptr这个变量的use增加,其他的HasPtr的use也会跟随着改变, *[目标变量一直就只有一个,所有的复制都只是改变指针而已] */ friend class HasPtr; int…
13.8 Write a smart pointer class. A smart pointer is a data type, usually implemented with templates, that simulates a pointer while also providing automatic garbage collection. It automatically counts the number of references to a SmartPointer<T*>…