[英]seg fault after end of function (C++)
我遇到段错误:11运行特定程序时。 在将系统升级到Mac OS X 10.9之前,我觉得这个问题并不存在,但是有可能我只是忽略了它。
无论如何,我的函数看起来像:
// this applies a warp to the field given, and saves output. simple!
void Apply(string warpName, string fieldName, bool conserve, string outName) {
// get lon, lat dimensions of warp
int noLongs = GetDimension(warpName, 3, "warp");
int noLats = GetDimension(warpName, 2, "warp");
int origNoLongs = noLongs, origNoLats = noLats;
// read in params
vector<double> params = ImportWarpFromNetCDF(warpName);
// rescale field to warp's dimensions, and read in
string tempName = "scaledField";
ReScale(fieldName, tempName, noLongs, noLats);
vector<vector<vector<double> > >inIntensities = ImportFieldFromNetCDF(tempName);
RemoveFile(tempName);
// just enter inIntensities for ref image, and 1 for lambda, to keep objective function happy
ObjectiveFunction objective(inIntensities, inIntensities, conserve, 1, false);
objective.setParameters(params);
// output files
ExportOutputToNetCDF(objective, outName);
cout << "BAH?!" << endl;
}
末尾的cout行只是在检查我是否正确到达了函数的结尾(我知道)。 有什么想法为什么会在这里出现段错误? 我知道,可能不知道单个函数调用的作用就很难分辨,因此,如有必要,我将添加它们。
实际上并没有太大关系,因为此函数是最后一个要调用的函数(因此seg错误不会中断任何操作),但是我还是想深入了解它!
函数“之后”发生的唯一事情是析构函数调用。 检查所有局部变量的析构函数。 看来, ObjectiveFunction
是唯一不是原始库或标准库容器的局部变量,因此请检查ObjectiveFunction::~ObjectiveFunction()
以了解潜在的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.