【问题标题】:_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) Error_BLOCK_TYPE_IS_VALID(pHead->nBlockUse) 错误
【发布时间】:2016-01-11 12:53:20
【问题描述】:

我在下面代码的最后一行遇到了错误“_BLOCK_TYPE_IS_VALID(pHead->nBlockUse)”:

pixelCoorindateAndThreePoint* tempSpace = new pixelCoorindateAndThreePoint[possibleMaxSize];
while (sscanf(temp, "%f %f", &cam1x, &cam1y)){
    location = (int)(file->length*cam1y + cam1x);
    file->cam1cam2ThreeDPoints[(int)(file->length*cam1y + cam1x)] = new pixelCoorindateAndThreePoint;
        sscanf(temp, "%*f %*f %f %f %f %f %f \n",
            &(tempSpace->PixelCoordinateCam2.x),
            &(tempSpace->PixelCoordinateCam2.y),
            &(tempSpace->threePoints.x),
            &(tempSpace->threePoints.y),
            &(tempSpace->threePoints.z));

        file->cam1cam2ThreeDPoints[location] = tempSpace;
        tempSpace++;

    temp = strtok(NULL, "\n");
}
    delete[] tempSpace;

为什么会出现这样的错误?由于我已经将这些指针值复制到file->cam1cam2ThreeDPoints,我应该能够删除tempSpace

【问题讨论】:

    标签: c++ arrays delete-operator


    【解决方案1】:

    tempSpace++; 改变指针。您需要记住最初分配的指针,以便用它调用delete

    【讨论】:

    • 或者更好的是,不要使用new。在这种情况下,请改用std::vector
    • @πάντα ῥεῖ 谢谢。我知道了。 5分钟后接受你的回答
    • @Martin Bonner 感谢您的建议。
    猜你喜欢
    • 2011-09-17
    • 1970-01-01
    • 1970-01-01
    • 2014-07-31
    • 1970-01-01
    • 2015-02-11
    • 2015-09-22
    • 2013-11-10
    • 1970-01-01
    相关资源
    最近更新 更多