相关疑难解决方法(0)

754
推荐指数
22
解决办法
55万
查看次数

检测到堆腐败 - 带指针的类

以下代码导致断言错误.此外,警告错误消息表示检测到堆损坏.

class A {
    int* a; // dynamic array of ints
    A() {};
    A(int size) {
        a = new int[size]; 
    }
    ~A() {
        delete [] a;
        a = nullptr;
    }
}

*** in code somewhere ***
int size = 5;
A temp = A(size);
Run Code Online (Sandbox Code Playgroud)

c++ constructor heap-corruption

1
推荐指数
1
解决办法
951
查看次数