我在運行特定程序時出現seg錯誤:11。我覺得像我之前升級我的系統的Mac OS X 10.9這個問題是不存在的,但它可能只是我忽略了它..函數結束後的seg fault(C++)
無論如何,我的函數看起來像:
// 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最後一行只是檢查我是否已經正確地結束了函數(我有)。任何想法爲什麼這將在這裏segfaulting?我很欣賞可能很難說沒有看到個別函數調用了什麼,所以我會在必要時添加這些函數。
它實際上並沒有太大的關係,因爲該功能被稱爲(所以賽格故障不會中斷任何東西)的最後一件事,但我還是寧願得到它的底部!
如果'cout'之後,但返回的功能之前,那麼這將是在局部變量之一的析構函數的段錯誤發生。你的調試器應該告訴你它到底發生了什麼。 –