unique-ptr

    7熱度

    1回答

    在閱讀關於將常量傳播包裝添加到標準庫(文檔號N4388)的提議時,我碰到了在紙: #include <memory> #include <iostream> struct A { void bar() const { std::cout << "A::bar (const)" << std::endl; } void bar()

    3熱度

    1回答

    如何在目標c類的接口部分中定義std :: unique_ptr的@property? @property std::unique_ptr<MyClass> ptr; 但我可以定義一個共享指針! 如果我定義唯一指針,然後我得到了錯誤: 不能因爲它的拷貝賦值運算符的分配是 隱含刪除

    3熱度

    1回答

    我想將unique_ptr<Foo>從vector<unique_ptr<Foo>>中移出。想想我的代碼: #include <vector> #include <memory> #include <iostream> using namespace std; class Foo { public: int x; Foo(int x): x(x) {};

    7熱度

    2回答

    我有一個簡單的Qt項目。我include <memory>但std :: unique_ptr不可用。我知道我應該使用Qt特定的智能指針,但我需要包含一個包含std :: unique_ptr的較大項目。 我該怎麼辦? 謝謝!

    7熱度

    1回答

    我有兩個集和一個迭代之間unique_ptr`s到的a一個元素: set<unique_ptr<X>> a, b; set<unique_ptr<X>>::iterator iter = find something in a; 我想從a去除由iter指向的元素,並將其插入到b。可能嗎?怎麼樣?

    5熱度

    3回答

    例如我很確定這是有效的。 int foo = 51; int* bar = &foo; foo = 3; 所以吧仍然有效,並且*bar == 3。 怎麼樣,如果我們說 std::unique_ptr<int> foo(new int(51)); // should probably use make_unique int* bar = foo.get(); foo.reset(new

    11熱度

    5回答

    我有一個函數需要返回指向類myClass的對象的指針。爲此,我使用std::unique_ptr。 如果函數成功,它將返回一個指向包含數據的對象的指針。如果失敗,應該返回null。 這是我的代碼skelepton: std::unique_ptr<myClass> getData() { if (dataExists) ... create a new myClass ob

    1熱度

    1回答

    我有一個回調傳遞給一個異步函數,它只負責刪除傳遞給異步函數的指針。 如何刪除指針: 通過使用顯式刪除。 通過創建將刪除對象的unique_ptr。 對於創建對象也有同樣的問題 - 我應該使用new還是創建一個unique_ptr並立即釋放它。 MyClass* myClass = make_unique<MyClass>().release(); AsyncFunc(myClass, [myCl

    1熱度

    2回答

    我宣佈一個類型像 template <typename T> using SmartPtr = std::unique_ptr<T, MyDeleter>; 在某些特定情況下,我想算到對象的引用,並有條件地刪除它時,指針會超出範圍。 我知道有一個的std :: shared_ptr的類,但我有一些對象我想通過一個通用的接口來訪問。這些對象中的一些屬於它們的類,其他類具有工廠方法,可以產生它們

    4熱度

    1回答

    我當前在將SDL_Window指針存儲爲std :: unique_ptr時遇到了問題。 我想什麼: std::unique_ptr<SDL_Window> window_; 解決辦法: std::unique_ptr<SDL_Window, void(*)(SDL_Window*)> window_; 第一次嘗試保存在內存頭引發錯誤,說SDL_Window是一個不完整的類型。嗯,我知道S