我收到此错误消息:
调试断言失败!
表达式:_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());
...
}
该错误似乎与排序功能有关。我检查了 nets 向量的所有实例,它们似乎没问题,具有不同的 sse。有趣的是,我为上面的代码创建了一个更简单的例子(见下文),它没有任何错误。我正在破坏我的大脑。请帮忙。
#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);
}