调试失败!表达式:_BLOCK_TYPE_IS_VALID [英] Debug Assertion Failed! Expression: _BLOCK_TYPE_IS_VALID

查看:610
本文介绍了调试失败!表达式:_BLOCK_TYPE_IS_VALID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我收到此错误讯息:


调试失败!

Debug Assertion Failed!

表达式:_BLOCK_TYPE_US_VALID(pHead-> nBlockUse)

Expression:_BLOCK_TYPE_US_VALID(pHead->nBlockUse)

尝试执行以下操作

#include <vector>
#include <algorithm>
using namespace std;

class NN
{
public:
    NN(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int UEW,const double *extInitWt);
    double sse;
    bool operator < (const NN &net) const {return sse < net.sse;}
};

class Pop
{
    int popSize;
    double a;
public:

    Pop(const int numLayers,const int *lSz,const int AFT,const int OAF,const double initWtMag,const int numNets,const double alpha);
    ~Pop();
    vector<NN> nets;
    void GA(...);
};

Pop::Pop(const int numLayers,const int *lSz,const int AFT,const int OAF,
         const double initWtMag,const int numNets,const double alpha)
{
    popSize=numNets;
    a=alpha;
    nets.reserve(popSize);
    for(int i=0;i<popSize;i++)
    {
        NN *net = new NN (numLayers,lSz,AFT,OAF,initWtMag,0,0);
        nets.push_back(*net);
    }
}

void Pop::GA()
{
...
        sort(nets.begin(),nets.end());
...
}

错误似乎与排序相关功能。我检查网络矢量的所有实例,他们似乎是好的,有不同的sse的。有趣的是,我创建了一个更简单的上述代码的情况(见下文),它的工作没有任何错误。我正在毁坏我的大脑。请帮助。

The error appears to be related to the sort function. I check all instances of nets vector and they seem to be OK, having different sse's. The funny thing is that I created a simpler case of the above code (see below) and it worked without any errors. I am wrecking my brain. Please help.

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;

class Student
{
public:
    string name;
    double grade;
    Student(string,double);
    bool operator < (const Student &st) const {return grade < st.grade;}
};

Student::Student(string stName,double stGrade)
{
    name = stName;
    grade = stGrade;
}

int main()
{
    vector<Student> group;
    Student *st;
    st = new Student("Bill",3.5);
    group.push_back(*st);
    st = new Student("John",3.9);
    group.push_back(*st);
    st = new Student("Dave",3.1);
    group.push_back(*st);
    sort(group.begin(),group.end());
    for each(Student st in group)
        cout << st.name << " " << st.grade << endl;
    cin.get();
    return(0);
}


推荐答案

_BLOCK_TYPE_IS_VALID断言触发,当您覆盖由 new 分配的块的标题时。当你切片对象,使用死对象等时,会发生这种情况。

The _BLOCK_TYPE_IS_VALID assertion gets fired, when you overwrite the header of an block allocated by new. This happens when you slice objects, use dead objects, etc.

你应该看看你的完整代码,并尝试从你的调试器中的数据。这个短代码片段包含几个好奇的C ++使用,但没有明显的点,这产生描述的错误(至少对我来说)。

You should have a look at your complete code, and try to work from the data you have in your debugger. This short code snippet contains several 'curious' usage of C++, but no obvious point at which this produces the described error (at least for me).

这篇关于调试失败!表达式:_BLOCK_TYPE_IS_VALID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆