gpt4 book ai didi

c++ - 函数结束后出现段错误 (C++)

转载 作者:行者123 更新时间:2023-11-30 01:18:58 25 4
gpt4 key购买 nike

当我运行特定程序时出现段错误: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 行只是检查我是否正确地到达了函数的结尾(我有)。关于为什么这会在这里出现段错误的任何想法?我明白如果不看各个函数调用的作用可能很难说清楚,所以我会在必要时添加它们。

这实际上并没有太大关系,因为这个函数是最后调用的东西(所以段错误不会中断任何东西),但我仍然宁愿追根究底!

最佳答案

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

关于c++ - 函数结束后出现段错误 (C++),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21727185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com