读书人

这个程序使用auto_ptr如何不报错?

发布时间: 2012-04-04 16:38:51 作者: rapoo

这个程序使用auto_ptr怎么不报错??

C/C++ code
#include <iostream>#include <memory>using namespace std;void bad_print(auto_ptr<int> &a){    if(a.get() == NULL)        cout << "NULL";    else        cout << *a;}int main(){    auto_ptr<int> p(new int(100));    *p = 42;    bad_print(p);    *p = 18;  // 报错?    return 0;}


C++标准程序库上的一个例子 话说这个注释的地方怎么不报错呢 我使用的是VS2010

[解决办法]
为什么要报错??auto_ptr只是在复制时候有副作用而已,也不是那么容易报错啊

读书人网 >C++

热点推荐