Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/152.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 功能结束后的seg故障(C+;+;)_C++_Segmentation Fault_Void - Fatal编程技术网

C++ 功能结束后的seg故障(C+;+;)

C++ 功能结束后的seg故障(C+;+;),c++,segmentation-fault,void,C++,Segmentation Fault,Void,当我运行一个特定的程序时,我有一个seg错误: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 lo

当我运行一个特定的程序时,我有一个seg错误: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;

}
//这将对给定的字段应用扭曲,并保存输出。易于理解的
无效应用(字符串warpName、字符串fieldName、布尔保存、字符串outName){
//获取经纱的经度、经纬度尺寸
int noLongs=GetDimension(warpName,3,“warp”);
int noLats=GetDimension(warpName,2,“warp”);
int origNoLongs=noLongs,origNoLats=noLats;
//读入参数
向量参数=ImportWarpFromNetCDF(warpName);
//将字段重新缩放为扭曲的尺寸,并读入
字符串tempName=“scaledField”;
重新缩放(字段名、临时名称、noLongs、noLats);
向量密度=ImportFieldFromNetCDF(tempName);
RemoveFile(tempName);
//只需为ref image输入inintenties,为lambda输入1,即可满足目标函数的要求
目标功能目标(inIntensities,inIntensities,conserve,1,false);
目的:设置参数(params);
//输出文件
exportOutputOneCDF(目标、名称);

cout函数“之后”发生的唯一事情是析构函数调用。请检查所有局部变量的析构函数。看起来,
ObjectiveFunction
是唯一一个不是基元或标准库容器的局部变量,所以请检查
ObjectiveFunction::~ObjectiveFunction()
查找潜在问题。

函数“之后”发生的唯一事情是析构函数调用。检查所有局部变量的析构函数。看起来
ObjectiveFunction
是唯一一个不是基元或标准库容器的局部变量,所以请检查
ObjectiveFunction::~ObjectiveFunction()
查找潜在问题。

如果segfault发生在
cout
之后但在函数返回之前,则它将位于一个局部变量的析构函数中。调试器应告诉您它发生的确切位置。如果segfault发生在
cout
之后但函数返回之前,则它将e在一个局部变量的析构函数中。调试器应该会告诉您它发生的确切位置。很好地发现,~ObjectiveFunction中有一个删除指针的调用,该指针不是为这种类型的ObjectiveFunction设置的!我现在将此删除封装在if子句中,这样我们就不会尝试删除不存在的东西。非常感谢!非常出色地发现,~ObjectiveFunction中有一个删除指针的调用,该指针不是为这种类型的ObjectiveFunction设置的!我现在将此删除包装在if子句中,这样我们就不会尝试删除不存在的内容。非常感谢!