auto-ptr

    2熱度

    3回答

    我想聲明中使用的「安全」 push()功能與auto_ptr這樣的: template<class StackType,typename T> inline void push(StackType &s, auto_ptr<T> p) { s.push(p.get()); p.release(); } 我也希望它爲空指針工作,例如: push(my_stack, 0);

    3熱度

    4回答

    對於下面的C++代碼,我得到一個編譯器錯誤: class Mkt { int k; public: Mkt(int n): k(n) { throw; } ~Mkt() { cout<<"\n\nINSIDE Mkt DTOR function:\t"<<endl; } void func1

    3熱度

    2回答

    說我有一個模板類 template<class T> class A; template<> class A<int> { public: void print(){ std::cout << "I am an int !" << std::endl; } }; template<> class A<double> { public:

    2熱度

    6回答

    我跑這個程序,但我沒有得到這個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()

    6熱度

    4回答

    我瞭解到STL可以禁止程序員將auto_ptr放入容器中。例如下面的代碼不會編譯: auto_ptr<int> a(new int(10)); vector<auto_ptr<int> > v; v.push_back(a); auto_ptr有複製構造函數,爲什麼這個代碼甚至可以編譯?

    0熱度

    2回答

    請幫我理解下面的問題。 看一下下面的代碼示例: #include <iostream> class Shape { public: virtual wchar_t *GetName() { return L"Shape"; } }; class Circle: public Shape { public: wchar_t *GetName() { return L"

    2熱度

    1回答

    我有一個抽象基類,它定義了數據接口的接口。數據匯的具體實現是通過工廠獲取的。爲了整理代碼,我爲factory方法創建了一個typedef,它從DataSink抽象基類中返回新的DataSink對象。 #include <memory> #include <string> class DataSink { public: DataSink() { } v

    1熱度

    5回答

    這個問題閱讀本教程後,提出了一個例子: http://www.cprogramming.com/tutorial/auto_ptr.html 那裏你可以找到下面的語句:此行爲的一個微妙的後果是,汽車 _ ptrs在所有情況下都無法正常工作。例如,將ptr對象與標準模板庫一起使用可能會導致問題,因爲STL中的某些函數可能會複製容器中的對象(如vector容器類)。一個例子是sort函數,它使得容器中

    4熱度

    2回答

    我正在閱讀關於共享指針的一些說明。 他們說,通過STL的第一次嘗試與auto_ptr的有以下主要缺點: 他們不能在STL容器中使用 複製auto_ptr的所有權轉移 有效地傳遞一個auto_ptr的功能使它成爲水槽 我明白前兩項,但我不確定最後一項的含義。 有人可以請解釋這一點。 謝謝。

    4熱度

    3回答

    我的一些同事喜歡在構造函數初始化列表中明確地初始化std::auto_ptr到0,但是它的構造函數中將被初始化爲0而不需要任何顯式的初始化。那麼是否有任何理由去做? #include <memory> class A { A() : SomePtr(0) { } private: std::auto_ptr<SomeType> SomePtr;