unique-ptr

    3熱度

    2回答

    我想將std::unique_ptr與FreeImage的FITAG結合使用。在純C的代碼是: ... load image; FITAG* tag = NULL; FreeImage_GetMetadata(FIMD_EXIF_EXIF, bitmap, "Property", &tag); ... do some stuff with tag; FreeImage_DeleteTag

    3熱度

    2回答

    我正在嘗試使用unique_ptr實現BST。我有一個shared_ptr的工作計劃。我該如何去使用unique_ptr來強制執行BinarySearchTree的單一所有權語義? 當我將shared_ptr替換爲unique_ptr時,我的編譯錯誤超出了我的理解範圍。 #include <iostream> #include <memory> template<class T> clas

    2熱度

    2回答

    我的目標是爲我的新圖書館提供abi兼容性。 我期待使用unique_ptr而不是原始指針。但是恐怕如果我更新標準庫,我可能會破壞阿比。這是真的嗎?未來的stdlib版本中是否有unique_ptrs的abi穩定性保證?

    0熱度

    1回答

    我目前正試圖包裝一個std :: ostringstream到和std :: unique_ptr。 我目前的代碼編譯,但在運行時,我得到分段錯誤。 當我不包裝它 - 使用舊的c樣式指針,它運行良好。 有關更詳細的概述,我正在使用curlpp將數據下載到ostringstream中。 這是我在做什麼: std::unique_ptr<std::ostringstream> data_stream;

    4熱度

    1回答

    我有一個類 class A { public: A(){cout<<"C";} ~A(){cout<<"D";} }; int main(){ unique_ptr<A> a(new A[5]); // - doesn't work unique_ptr<A> a(new A[1]); // - doesn't work unique_ptr

    1熱度

    1回答

    我想擁有一個託管指針(唯一或共享),並且能夠用新的內存重新分配它,並且確保舊的內存被刪除(因爲它應該是)與託管指針。 struct MyStruct { MyStruct(signed int) { } MyStruct(unsigned float) { } }; std::unique_ptr<MyStruct> y(new MyStruct(-4)); // i

    1熱度

    1回答

    我有std::list的std::unique_ptrs到Entity對象。當我試圖循環瀏覽它們時,程序會說列表中的項目是不可訪問的。該列表是一個成員變量,聲明爲private:列表< unique_ptr>。 void EntityContainer::E_Update(int delta) { for (auto& child : children) child->Up

    2熱度

    1回答

    這段代碼有什麼問題嗎? #include <memory> class Foo { }; class Bar { std::unique_ptr<Foo> foo_; }; int main() { Bar bar; Bar bar2 = std::move(bar); } 我得到這個錯誤: 1>c:\users\szx\documents\vi

    3熱度

    2回答

    Accroding到http://en.cppreference.com/w/cpp/memory/unique_ptr/reset, void reset(pointer ptr = pointer()); template< class U > void reset(U) = delete; void reset(std::nullptr_t p); 1)鑑於current_pt

    1熱度

    2回答

    我很難理解獨特指針的所有權。 任何人都可以解釋如何將指針存儲到集合中的唯一指針嗎? typedef std::pair<SceneNode*, SceneNode*> Pair; typedef std::unique_ptr<SceneNode> Ptr; std::vector<Ptr> mChildren; void SceneNode::checkSceneCollision(