动态实例化类,然后立即将其删除

Dynamically instancing a class then deleting it right away?

本文关键字:删除 然后 实例化 动态      更新时间:2023-10-16

我创建了自己的类,但是当我尝试实例化它时,我遇到了一堵墙。

这是我的代码:

m_interpolation = new Interpolation(m_mesureList, width, height, parent);
delete m_interpolation;

这将生成错误:

0B3E9E40 处的堆块在 0B3E9E68 处修改,请求的大小为 20

看不出我做错了什么...

有关信息,这里是我的类 Interpolation.h 和 Interpolation 的完整定义.cpp如果这有任何帮助的话。

添加了一个析构函数,但仍然没有解决问题。

Interpolation::~Interpolation()
{
    delete m_progress;
    m_progress = 0;
}

在 ctor 中:填充m_w:最多 (m_N-1)

for (int i(0); i < m_N; ++i)
{
    m_pt.push_back(QPointF(mesureList[i]->getX(), mesureList[i]->getY()));
    m_w.push_back(mesureList[i]->getAngle());
}

稍后:访问m_w[m_N],超出向量的末尾

for (i = m_N; i >= 0; --i)
{
    sum = m_w[i];
    for (j = i+1; j < m_N; j++) sum -= LU[i][j]*m_w[j];
    m_w[i] = sum / LU[i][i];
}

构造函数 Interpolation::Interopolation() 或析构函数 Interpolation::~Interpolation() 中的某些内容超出了对象的大小。