构建并运行此代码时,出现“检测到堆栈粉碎”错误:
这是因为unique_ptr发生了吗?
#ifndef BVECTOR_H
#define BVECTOR_H
static const int MIN_CAPACITY = 16;
#include <memory>
class BVector
{
public:
BVector() = delete;
BVector(int);
~BVector() = default;
private:
int _size{0};
int _capacity{MIN_CAPACITY};
std::unique_ptr<int[]> data;
};
#endif // BVECTOR_H
#include "bvector.h"
#include <iostream>
#include <memory>
BVector::BVector(int init_size)
{
data = std::unique_ptr<int[]>(new int[init_size]);
}
#include <iostream>
//#include <assert.h>
#include "bvector.h"
int main()
{
BVector vec(5);
//BArrayTest tester;
//tester.runTests();
return 0;
}
为什么会这样?我对堆栈粉碎了解不多,但是在此简单代码中我没想到它。