effictive c++ item14中的疑问
item 14有如下描述:
Copy the underlying resource. Sometimes you can have as many copies of a resource as you like, and the only reason you need a resource-managing class is to make sure that each copy is released when you're done with it. In that case, copying the resource-managing object should also copy the resource it wraps. That is, copying a resource-managing object performs a "deep copy."
Some implementations of the standard string type consist of pointers to heap memory, where the characters making up the string are stored. Objects of such strings contain a pointer to the heap memory. When a string object is copied, a copy is made of both the pointer and the memory it points to. Such strings exhibit deep copying.
其中
copying the resource-managing object should also copy the resource it wraps.复制资源管理的对象是,应该同时复制其所指向的对象。结合紧接着的那个string的例子,复制string object时,应该复制指针和指针所指的对象。
我的问题是这样的,既然要同时复制指针所指的对象,不就是相当于重新构造出了此类的另外一个对象了么?那std::tr1::shared_ptr所指的岂不总是一个对象,那和std::auto_ptr还有什么区别啊?
请问这个item的这个部分该怎么去理解?
[解决办法]
应该是指向同一内存,另外这个智能指针好象应该还有个内部记数器,当记数器值为0时才销毁该内存,大于0时不销毁。
不知理解的对不对。