您好,我一直在尝试解决我目前正在处理的代码中遇到的问题。我看过其他帖子,但找不到任何相关内容。
基本上,我已经添加了所有必要的文件:头文件和源文件,但仍然出现错误。其中之一是“‘setValue’:未找到标识符
”。出于某种原因,它无法识别我的头文件中的任何函数。
无论如何,这是与错误有关的代码部分。我无法显示所有代码,因为它太大了:
header DoubleVector.h:
#pragma once
#pragma warning(disable : 4251)
#ifndef DOUBLEVECTOR_H_
#define DOUBLEVECTOR_H_
#define _USE_MATH_DEFINES // need to use M_PI
#include <math.h>
#include "PMath.h"
// whole bunch of constructors and functions declarations, which I won't show
// this is one of the functions that's causing trouble
void SetValue(long index,double val);
来源 DoubleVector.cxx:
void CDoubleVector::SetValue(long index,double val)
{
if(index < 0 || index >= m_nSize)
{
//string message("Index out of range of vector.");
//throw PMathError(message);
throw PMathError("Error: index(%d) out of range. <- void SetValue(long index, double val) in DoubleVector.cxx",index); // tested
}
m_pData[index] = val;
}
我在其中调用我的函数 variogram.cc 的文件:
#include "variogram.h"
#include "DoubleVector.h"
void Variogram::estimate() {
base_multimin_function_fdf fdf;
fdf.n = _spatialCorrFunc.param.size();
fdf.f = &minimizationf;
fdf.df = &minimizationfd;
fdf.fdf = &minimizationfdf;
fdf.params = this;
long iter = 0;
int status;
//gsl_vector *x = gsl_vector_alloc(fdf.n);
for (int i = 0; i < fdf.n; ++i) {
if(i < 3)
//gsl_vector_set(x, i, sqrt(_spatialCorrFunc.param[i]));
//Greg: void SetValue(long index, double val) as an alternative //to gsl_vector_set(...)
SetValue(i,sqrt(_spatialCorrFunc.param[i]));
else//kappa
SetValue(i, _spatialCorrFunc.param[i]);
}
这件事让我发疯,但我确信这是我没有看到的愚蠢行为。 提前致谢。
最佳答案
void SetValue(long index,double val); // Notice that beginning `S` is uppercase.
setValue
=> S
在方法调用的开头应该是大写。
关于c++ - 在 C++ 中找不到相同的旧标识符错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7356366/