c++ 类内部 使用 new delete

低级错误:

 /**
* @clusterNums 默认为5 分类数目
* @xyVector 处理后点云数据 x y顺序存储
*/
int GMM::runGMM(int clusterNums, const std::vector<db::Point2f> & xyVector, std::vector<db::pointCuster> & xyCusterVector){ int dim = ; datanums = xyVector.size();
data = new double*[datanums]; for (int i = , j = ; j < xyVector.size(); j++, i++)
{
data[i] = new double[dim];
data[i][] = xyVector[j].x;
data[i][] = xyVector[j].y;
}
GMM gmm;
result = gmm.GMM_Cluster(data, datanums, dim, clusterNums);
//multimap<int, pair<double, double>>cluster;
vector<vector<int>>clusters;
clusters.resize(clusterNums); for (int i = ; i < datanums; i++)
{
//cluster.insert(pair<int, pair<double, double>>
// (result[i], pair<double, double>(data[i][0], data[i][1])));
clusters[result[i]].push_back(i);
//cout << result[i] << endl;
} for (int i = ; i < clusterNums; i++)
{
db::pointCuster tempCuster;
xyCusterVector.push_back(tempCuster); for (int j = ; j < clusters[i].size(); j++)
{
db::Point2f tempPoint;
xyCusterVector[i].push_back(tempPoint); xyCusterVector[i][j].x = data[clusters[i][j]][];
xyCusterVector[i][j].y = data[clusters[i][j]][];
}
} return ;
}

总结:一定不要在类的内部,实例化它自己的对象,导致内存释放错误。

上一篇:干货!表达式树解析"框架"(2)


下一篇:Jquery网页选项卡应用