destructor

    2熱度

    2回答

    在我的賦值操作方法我第一次銷燬該對象管理的任何資源,然後分配,所以: struct Animal { int aNumber; int * buffer; Animal() { buffer = new int[128]; } Animal& operator= (Animal& other) { if (this != &other

    4熱度

    4回答

    下面的代碼編譯,但在運行時提供了一個錯誤的連續內存塊: # include <iostream> # include <string.h> class A { public: A() {} A (int id, char * t_name) { _id = id ; name = new char [ strlen (t_name) + 1 ] ;

    0熱度

    1回答

    我想知道你們中的一個人是否可以確認我正確地刪除了一些動態分配的內存。 的TileWrapper下面被初始化爲指針的二維數組: private: TileWrapper*** mLayout; 我已經簡化初始化向您展示的重要組成部分: void generateLayout() { mLayout = new TileWrapper**[mRows]; for(in

    1熱度

    2回答

    所以我製作了一個模擬井字遊戲的程序,並用valgrind運行它,它說我有內存泄漏。什麼是造成這種泄漏,我該如何解決? 這裏是從Valgrind的輸出: ==15253== ==15253== HEAP SUMMARY: ==15253== in use at exit: 72,704 bytes in 1 blocks ==15253== total heap usage: 37 allo

    1熱度

    1回答

    假設我們有一個簡單的結構: struct RefCounters { size_t strong_cnt; size_t weak_cnt; RefCounters() : strong_cnt(0), weak_cnt(0) {} }; 從實現的角度,析構函數RefCounters::~RefCounters應該什麼都不做,因爲它的所有成員都有基本類型。這意味

    0熱度

    3回答

    #include <iostream> #include <cstring> #include <vector> using namespace std; class items{ char * name; public: items(const char * str){ int len = strlen(str); this->name

    4熱度

    4回答

    我知道,當爲您提供隱式構造函數時,您的類成員將從左到右和從上到下進行初始化。換句話說,按照他們聲明的順序。然後,當類對象超出範圍時,所有成員都以相反的順序被破壞。但是,如果我必須自己銷燬成員,我是否必須按照列出的順序來執行操作?例如: struct Dog {}; struct Animal { Dog* dog1 = new Dog; Dog* dog2 = new D

    1熱度

    2回答

    如果需要,可以通過參數的構造函數將參數傳遞給類。 class Test { public function __construct($echo) { echo $echo; } } $test = new Test('hello'); // Echos "hello" 是否有任何方法將參數傳遞給__destruct? class Test {

    7熱度

    2回答

    我用我的代碼就地析構函數,類似這樣的精簡一段代碼: #include <new> #include <stdlib.h> struct Node { }; int main(int, char**) { Node* a = reinterpret_cast<Node*>(malloc(sizeof(Node))); new(a) Node; Node*

    0熱度

    2回答

    有沒有一種方法可以在C++中確定一個方法在運行時是否是純虛擬的?事實上,問題是如果有一種方法可以知道派生類的析構函數是否已經被執行,但是基類仍然存在。 這是我的情況下(簡化): class BaseClass{ private: class ThreadUtil *threadUtil; public: Mutex mutex; ~BaseClass(){