- #1
CAF123
Gold Member
- 2,948
- 88
Hello all, see below for a snippet of a header file, class1.h, and source code file, class1.cpp, adjusted to reproduce the issue I am having. I have declared a series of functions in the .h file and their corresponding definitions in the .cpp file but when I compile I get the error:
class1.cpp:48:57: error: cannot initialize a parameter of type 'double (*)(double, void *)'
with an rvalue of type 'double (class1::*)(double, void *)'
convolute1(lowerBound,split,epsabs,epsrel,toystruct1,&class1::func1);
I think it is to do with how I declare the function convolute1 in the .h file involving the pointer and maybe there is some casting issue. I have tried a few things including making the func1 static but this gives me problems elsewhere in the code (not reproduced in the toy files below) so I was wondering if anyone could see an issue immediately? Thanks!
Header file, class1.h:
Source code file, class1.cpp:
class1.cpp:48:57: error: cannot initialize a parameter of type 'double (*)(double, void *)'
with an rvalue of type 'double (class1::*)(double, void *)'
convolute1(lowerBound,split,epsabs,epsrel,toystruct1,&class1::func1);
I think it is to do with how I declare the function convolute1 in the .h file involving the pointer and maybe there is some casting issue. I have tried a few things including making the func1 static but this gives me problems elsewhere in the code (not reproduced in the toy files below) so I was wondering if anyone could see an issue immediately? Thanks!
Header file, class1.h:
C++:
class class1 {
struct toystruct_t {
double a,b,c;
};
double func1(double z, void *p);
double func2(toystruct_t toystruct);
double convolute1(double lowerBoundary, double upperBoundary, double epsabs, double epsrel, toystruct_t toystruct, double func(double, void *));
};
Source code file, class1.cpp:
C++:
#include <iostream>
#include <gsl/gsl_integration.h>
#include <math.h>
#include <complex>
#include "class1.h"
struct toystruct_t
{
double a,b,c;
};double class1::func1(double z, void *p)
{
return 2.0; //function here made trival as reproduces error I wish to discuss without adding further complication
}
double class1::convolute1(double lowerBoundary, double upperBoundary, double epsabs, double epsrel, toystruct_t toystruct, double func(double, void *))
{
double result;
double err;
double res;
gsl_integration_workspace * coeffIntegralWorkspace = gsl_integration_workspace_alloc (1e8);
gsl_function F;
F.params = (void*)(&toystruct);
F.function = func;
gsl_integration_qags(&F, lowerBoundary, upperBoundary,
epsabs, epsrel, 1e8,
coeffIntegralWorkspace, &result, &err);
gsl_integration_workspace_free(coeffIntegralWorkspace);
res = result;
return res;
}
double class1::func2(toystruct_t toystruct1)
{
double lowerBound = -10.0;
double upperBound = -4.0;
double epsabs=1e-3;
double epsrel=1e-3;
double res =
convolute1(lowerBound,upperBound,epsabs,epsrel,toystruct1,&class1::func1);
return res;
}
int main(int argc, const char * argv[]) {
std::cout << "Hello World" << std::endl;
}
Last edited by a moderator: