unique-ptr

    0熱度

    1回答

    當引用刪除功能我有下面的類定義: class InterpolatedSpreadConnector { public: ~InterpolatedSpreadConnector() = default; GPUImage* operator()() override; GPUImage* AncestorReducedConnectivity = nullpt

    1熱度

    1回答

    從:http://en.cppreference.com/w/cpp/memory/unique_ptr 問題:爲什麼close()方法被調用只有FP不爲空? std::unique_ptr<std::FILE, decltype(&std::fclose)> fp(std::fopen("demo.txt", "r"), &std::fclose);

    2熱度

    1回答

    如何在類的構造函數中創建new並將值分配給私有unique_ptr? Tyvm:^)基思 我盡力而爲: #include <iostream> #include <memory> class A { public: A() {}; A(int); void print(); private: std::unique_ptr<int> int_ptr

    2熱度

    2回答

    學習C++我正在編寫一個遊戲。在這個遊戲中,可以有兩個玩家。這些玩家可以通過套接字互相連接。添加一個帶有唯一指向播放頭的指針的向量後,我得到了錯誤:「Error C2280'std :: unique_ptr> :: unique_ptr(const std :: unique_ptr < _Ty,std :: default_delete < _Ty >> &)':attempting引用已刪除

    2熱度

    1回答

    我有一個向量或遊戲對象。我必須編譯的C++ 11 std::vector< std::unique_ptr<Game> > games_; 遊戲是基類,像這樣 class Game { public: Game(int id, const std::string& name) : id_(id), name_(name){} virtual ~G

    6熱度

    2回答

    無法理解這是爲什麼失敗? int *p = new int(10); std::unique_ptr<int> ptr(p); // Below line gives compilation error. std::cout << "Value of ptr " << ptr << std::endl; // Below line works well. std::cout << "V

    2熱度

    1回答

    隨着reinterpret_cast,將是這樣的: std::unique_ptr< const T , void (*) (const T *) > to_const (std::unique_ptr< T , void (*) (T *) > &ptr) { return { ptr.release() , reinterpret_cast< void (*) (c

    0熱度

    1回答

    /* 清理堆分配的資源這是我的理解是,它加載一個或多個動態鏈接庫(DLL)到其地址空間Windows進程將與所有加載的共享地址空間DLL--意味着這些DLL可以讀取和寫入進程地址空間中的任何內存。但是,如果在堆上分配對象,則每個模塊(無論是.exe還是某個進程的加載的DLL)都從它自己的堆中分配。由於這個原因,對於執行分配的同一個堆釋放內存非常關鍵。 這一切都對我有意義,我認爲我可以使用std

    1熱度

    2回答

    修改了一些舊的代碼,我手動處理了一個向量指針的生命期到抽象基類(ABC)的具體實例。 所以矢量的主人有哪些手動經歷,並刪除了矢量內容的虛擬析構函數等 由於矢量的所有者擁有它的元素,這讓很多的意義,這種改變unique_ptr的向量。 不幸的是,這似乎是不可能的?因爲vector<unique_ptr<type>>必須能夠有一個靜態的析構函數用於type但由於在這種情況下,類型是ABC,這是不可用,

    2熱度

    1回答

    我正在使用黑盒框架(cdg),它使用值填充uint32_t的數組。 調用看起來像這樣: std::size_t dataCount = 100; uint32_t* data = new uint32_t[dataCount]; cdg.generate(data); 不幸的是,框架不使用模板,所以我有一個uint32_t*通過。爲了擺脫原始指針,我想將它「包裝」成std::unique_