我运行了这个程序,但我不明白这个 auto_ptr 的作用以及它显示值的基础是什么?
int main(int argc,char **argv)
{
int *i= new int;
auto_ptr<int> x(i);
auto_ptr<int>y;
y=x;
count <<x.get()<<endl;
count <<y.get()<<endl;
}
最佳答案
此代码将为第一个 auto_ptr 对象打印 NULL 地址,为第二个对象打印一些非 NULL 地址,表明源对象在赋值过程中丢失了引用 (=)。
关于c++ - 这个 auto_ptr 程序是如何工作的,它做了什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6147717/