unique-ptr

    0熱度

    1回答

    爲什麼我不能這樣做? typedef boost::interprocess::unique_ptr<QueueList, QueueListDeletor> UQList; typedef boost::intrusive::list<UQList> List; // Compiler (VS 2003) complains 的QueueList是從public boost::intrus

    42熱度

    3回答

    我與unique_ptr和右值移動哲學混淆。 比方說,我們有兩個類別: std::vector<std::auto_ptr<int>> autoCollection; std::vector<std::unique_ptr<int>> uniqueCollection; 現在我希望下面的失敗,因爲沒有告訴什麼算法內部做,也許使內部樞副本之類的,這樣翻錄離開auto_ptr的所有權: std:

    7熱度

    3回答

    說我有一個class T的std::list的: std::list<T> l; 當傳遞入的功能,我會用一個參考: someFunction(std::list<T> &l) 傳遞std::list的unique_ptr s的最佳方式是什麼? std::list< std::unique_ptr<T> > l; 像這樣: someFunction(std::unique_ptr<T>

    2熱度

    3回答

    我的代碼中的某處我有一個本地的std::unique_ptr<T>。我需要做的東西與指向的對象,我用一個函數,該函數: std::unique_ptr<T> some_function(std::unique_ptr<T> &t) { // do stuff return t; } 我這樣調用該函數: std::unique_ptr<T> some_T_ptr(new

    1熱度

    1回答

    我有一個for循環遍歷一個XML文檔,並找到一個指定的屬性,指向當前節點的指針位於boost :: interprocess :: unique_ptr中,並有一個自定義的deletor調用對象的release()函數。看起來,在每次循環迭代中,指針都被刪除,但是當這種情況發生時,函數會拋出。 任何人都可以提出解決方案嗎?我想到了實施機制,以檢查它是否應該被刪除,但我不知道我怎麼會做... 代碼:

    2熱度

    5回答

    好的,所有人都知道應該像瘟疫一樣避免原始指針,並且更喜歡智能指針,但是在實現容器時這個建議是否適用?這就是我試圖完成: template<typename T> class AVLTreeNode { public: T data; unique_ptr<AVLTreeNode<T>> left, right; int height; } 的unique_pt

    6熱度

    3回答

    這能正常工作嗎? (請參閱示例) unique_ptr<A> source() { return unique_ptr<A>(new A); } void doSomething(A &a) { // ... } void test() { doSomething(*source().get()); // unsafe? // When

    5熱度

    1回答

    #include <vector> #include <memory> using namespace std; class A { public: A(): i(new int) {} A(A const& a) = delete; A(A &&a): i(move(a.i)) {} unique_ptr<int> i; }; clas

    66熱度

    4回答

    在傳入的C++標準中auto_ptr會被棄用嗎? unique_ptr是否應該用於所有權轉移而不是shared_ptr? 如果unique_ptr不在標準中,那麼是否需要使用shared_ptr?

    7熱度

    2回答

    當我意識到C++ 11增加了unique_ptr s時,我一直在尋找一種方法來做安全向量和動態指針映射。我研究瞭如何在Google上使用它們,但在查找細節方面一直沒有成功。我需要知道以下內容: 除了自動內存收集之外,指針和unique_ptr之間究竟有什麼不同? 我該如何去除矢量或地圖中的unique_ptr?除了擦除迭代器之外,還有什麼特殊的代碼需要使用嗎?