【发布时间】:2014-02-12 11:51:47
【问题描述】:
运行特定程序时出现段错误: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 行只是检查我是否正确地到达了函数的末尾(我有)。关于为什么这会在这里出现段错误的任何想法?我很感激如果不查看各个函数调用的作用可能很难判断,因此我会在必要时添加它们。
其实没什么大不了的,因为这个函数是最后被调用的(所以段错误不会中断任何东西),但我还是更愿意深入了解它!
【问题讨论】:
-
如果段错误发生在
cout之后但在函数返回之前,那么它将位于局部变量之一的析构函数中。您的调试器应该准确地告诉您它发生的位置。
标签: c++ segmentation-fault void