auto-ptr

    1熱度

    2回答

    auto_ptr on wikipedia表示「一個包含STL容器的auto_ptr可能被用來阻止對容器的進一步修改」。它使用了下面的例子: auto_ptr<vector<ContainedType> > open_vec(new vector<ContainedType>); open_vec->push_back(5); open_vec->push_back(3); // Tra

    0熱度

    1回答

    我目前正在嘗試爲我正在處理的項目的cml(http://www.cmldev.net/)數學庫編寫一個基本包裝。 我有它有一個私有成員CML的矢量類的包裝 #ifndef VECTOR3_H_ #define VECTOR3_H_ #include "cml\cml.h" #include <memory> namespace Math { template<typenam

    0熱度

    3回答

    如果我有一個類 template <typename T> struct C { ... private: auto_ptr<T> ptr; }; 如何定義拷貝構造函數C: 它不能 template <typename T> C<T>::C(const C& other) ,因爲我想,如果我複製其他auto_ptr,我通過刪除 所有權來改變其他。 是合法的定義拷貝構造

    1熱度

    2回答

    你能告訴我這段代碼有什麼問題嗎?我被問這個在接受採訪時,我不知道什麼地方錯了 tClass是一個測試類,打印tClass成員的方法printSomething。 tClass * A = new tClass(); f(A); A->printSomething(); auto_ptr<tClass> * B = new tClass(); f(B); B-> printSomethi

    2熱度

    2回答

    我想包裝一個使用auto_ptr的C++庫。我正在使用swig 並希望生成python綁定。我看過關於如何在智能指針here上使用swig的swig文件部分。但我無法讓它工作。 痛飲生成希望使用一個const 參考初始化auto_ptr的代碼,但auto_ptr的限定具有非const 參考拷貝構造例如auto_ptr(auto_ptr &)。生成的 代碼不會使用「丟棄const限定符」進行編譯。當

    2熱度

    2回答

    我想使用智能指針,如auto_ptr,shared_ptr。但是,我不知道如何在這種情況下使用它。 CvMemStorage *storage = cvCreateMemStorage(); ... use the pointer ... cvReleaseMemStorage(&storage); 我不確定,但我認爲存儲變量只是一個malloc'ed內存,而不是C++類對象。有沒有辦法將

    42熱度

    3回答

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

    2熱度

    3回答

    std :: auto_ptr缺少const拷貝構造函數,因此我不能直接在集合中使用它。有沒有一些方法,例如向量的std :: auto_ptr,而不使用boost指針集合模板?

    3熱度

    5回答

    我目前正在研究2D遊戲引擎,並且已經閱讀過有關auto_ptr的內容,以及您應該如何將它們放在標準容器中。 我的引擎具有這樣的結構: StateManager - 有很多 - >國。 在引擎之外的主體中創建和分配狀態。我希望引擎存儲所有狀態的列表/矢量,以便在命令之間切換它們。 例如: SomeState *test = new SomeState(); StateManager->regi

    1熱度

    2回答

    請任何人可以解釋this code from C++ Reference site: #include <iostream> #include <memory> using namespace std; int main() { auto_ptr<int> p; p.reset (new int); *p=5; cout << *p << endl