Hello I've been trying to resolve the issue that I've been having with the code I am working on at the moment. I have looked at other posts but couldn't find anything relevant.
Basically, i have added all the necessary files: header and source files but still getting errors. One of many is "'setValue': identifier not found
". For some reason, it doesn't recognize any of the functions from my header file.
Anyways, here is the portion of the code that pertains to the error. I can't show all the code as its huge:
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);
Source 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;
}
File where I am calling my functions 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]);
}
This thing is driving me crazy but I am sure it's something stupid that I'm not seeing. Thanks in advance.
void SetValue(long index,double val); // Notice that beginning `S` is uppercase.
setValue
=> S
should be upper case at the beginning in the methods call.
You're using a member function without having an instance. You need to create an object and then call it on that object:
CDoubleVector dv;
...
dv.SetValue(i, sqrt(_spatialCorrFunc.param[i])); // etc
You can only use the plain SetValue(something)
when you're inside a member function in the class that has the member SetValue
, in which case it's shorthand for this->SetValue(something)
. That way the compiler knows what object you're talking about.
Not to mention your capitalisation is was wrong.
精彩评论