unique-ptr

    1熱度

    1回答

    #include <iostream> #include <memory> std::unique_ptr<int[]> addElement(int *myNumbers, int sizeOfArray); void printArray(int * arr_ptr, int sizeOfArray); int main() { const int SIZE = 5;

    4熱度

    3回答

    我想問一個關於構造函數中內存泄漏的問題。讓我們考慮一個類: class Foo { public: Foo(){ throw 500;} }; 是什麼在我看來 std::unique_ptr<Foo> l_ptr = std::make_unique<Foo>(); 和 std::unique_ptr<Foo> l_ptr; l_ptr.reset(new Fo

    2熱度

    1回答

    我創建這種載體,其具有緩衝器: std::vector<std::unique_ptr<locked_buffer<std::pair<int, std::vector<std::vector<unsigned char>>>>>> v1; 然後,我填充n緩衝器這個矢量和這個緩衝器具有aux元件。 n是一個int數,它是一個參數。 aux也是一個int類型的另一個參數。 for(int i=0

    9熱度

    1回答

    所有的標題。它會更容易讀/寫我的例子中的第二行,因爲模板參數的類型是顯而易見的: #include <memory> struct Foo{}; int main() { // redundant: good auto foo1 = std::unique_ptr<Foo>(new Foo()); // without explicitness: does

    2熱度

    1回答

    我需要使用智能指針的應用程序有幾個層次的類。調試代碼時的一個難點是在Visual Studio 2015的監視窗口內的智能指針(例如unique_ptr)的視圖。它總是同時顯示[ptr],[deleter]和[Raw View],而我主要關心的是快速查看[ptr]的內容時擴展指針的視圖。有沒有一種方法可以使調試變得更容易,並且可以自定義顯示智能指針內容的視圖,使其與Visual Studio 20

    1熱度

    1回答

    對於指向C++數組的原始指針,首先N個條目的內容可以通過將表達式帶入Visual Studio的Watch窗口中,並追加一個逗號,後面跟隨您想要查看的元素數。 (例如:testArray, 10)。在使用智能指針創建數組時,如何在Watch窗口中看到相同的內存內容? (例如unique_ptr<int[]> testArray = make_unique<int[]>(100)和我們想看到的第一1

    0熱度

    1回答

    我寫了結構MyParam,以便它可以使用任意數量的參數進行實例化,在本例中爲int和bool。出於封裝原因,我希望MyParams包含自己的promise,以便它可以報告何時完成某件事情。但是當我將這個語句添加到結構中時,它失敗了。儘管如此,作爲一個全球性的公司,它運作良好下面是代碼: #include <tuple> #include <memory> #include <future>

    1熱度

    1回答

    當我正在與我應該使用哪種樣式的c樣式函數進行交互時。 我打算從c函數返回後將數據存儲在向量中。一個優於另一個有什麼優勢? { auto test = std::make_unique<double[]>(10); fooCstyle(test); } 或 { auto test = std::vector<double>; test.reserve(1

    5熱度

    3回答

    是否可以使用std:fill來填充unique_ptr s的數組?其目的是對使用相同參數初始化的不同對象有不同的指針。 例如: std::unique_ptr<int> ar[3]; std::fill(ar.begin(), ar.end(), make_unique_for_each_element_somehow<int>(1));

    1熱度

    2回答

    我想使用unique_ptr與我的刪除程序。 我想我的我的unique_ptr與我的刪除器完全兼容與unique_ptr與默認deleter。 我這樣做: template <typename T> struct QObjectDeleteLaterDeletor : public std::default_delete<T> { void operator()(T *p