簡體   English   中英

功能結束后出現段錯誤(C ++)

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM