auto-ptr

    4热度

    1回答

    为什么auto_ptr中有模板拷贝构造函数和覆盖操作符函数? C++的ISO标准为auto_ptr指定了以下接口。 (这是直接复制了2003年的标准。) namespace std { template <class Y> struct auto_ptr_ref {}; template<class X> class auto_ptr { public:

    0热度

    2回答

    一个auto_ptr 您好我有一个编译错误,当我运行此代码: std::auto_ptr<MyDisplay> m_display = std::auto_ptr<MyDisplay>(new MyDisplay(this, m_displayController)); 错误是这个: error C2664: 'MyDisplay::MyDisplay(DemoWindow *,Di

    1热度

    3回答

    我想创建一个函数,它的auto_ptr到Base类,我想用auto_ptr到Derived类调​​用它。但是我没有完成它。 我一直在使用它没有一个参考的尝试: void function(std::auto_ptr<Base> ptr); std::auto_ptr<Derived> derivedPtr(new ...) function(derivedPtr); // error: #3

    5热度

    1回答

    我收到了一个编译器错误,并注意到一些有趣的事情。出于某种原因,unique_ptr有auto_ptr过载,但我认为auto_ptr被弃用: /usr/local/include/c++/4.9.0/bits/unique_ptr.h:228:2: note:template<class _Up, class> std::unique_ptr<_Tp, _Dp>::unique_ptr(std:

    6热度

    3回答

    考虑下面的代码: std::auto_ptr<std::string> p; if (p.get() == 0) { ... } 是在get()成员函数用于检查p尚未初始化的标准和可靠的方式?不管平台,编译器,编译器的优化标志等,它总会返回0吗?

    1热度

    2回答

    据我所知,auto_ptr不能与矢量一起使用,因为auto_ptr不符合作为可复制构造的要求。由于被复制的auto_ptr被修改,因此复制不会导致两个完全相同的副本,从而违反了可复制构造方式。 Unique_ptr也似乎也这样做;它修改被复制的对象 - 被复制对象的指针成员被设置为nullptr。 那么,怎么可能使用uinque_ptr与矢量而不是auto_ptrs? 我的理解是否正确或我在这里错

    2热度

    2回答

    我想弄清楚这段代码打印的内容,但由于某种原因我无法输出它,它给了我一个错误:“1 [main] Q1c 5752 open_stackdumpfile:转储堆栈跟踪到Q1c.exe.stackdump“。 double *dp=new double(1.2); auto_ptr <double> autodp1(dp); auto_ptr <double> autodp2=autodp1;

    3热度

    4回答

    为什么我会用get()和*,而不是仅仅调用*? 考虑下面的代码: auto_ptr<int> p (new int); *p = 100; cout << "p points to " << *p << '\n'; //100 auto_ptr<int> p (new int); *p.get() = 100; cout << "p points to " << *p.get()

    -2热度

    1回答

    double **mat; int i,j; mat=new double *[a]; for(i=0;i<a;i++) { mat[i]=new double [b]; } return(mat); 我写了这段代码来分配内存。我面临错误的内存分配错误。这个特殊的函数在我的代码中被调用超过10000次。我想在分配内存时使用auto_ptr。请帮我解决这个问题。

    4热度

    1回答

    我想了解有关auto_ptr类如何工作的某些细节。假设你有以下课程(我在一个网站上发现了这个人,他解释了赋值运算符的更精细的点)。 class TFoo : public TSuperFoo { auto_ptr<TBar> fBar1; auto_ptr<TBar> fBar2; public: TFoo& TFoo::operator=(const TFoo&