I am a newbie in c++ and I am trying to modify a code and use gsl_integration
library of c in a class called Cosmology. In order to assign member functions to to form a pointer for gsl, I used callback procedure I found by looking up in internet
Update: Cosmology.h
#include <cmath>
#include <gsl/gsl_integration.h>
struct CCallbackHolder
{
Cosmology* cls;
void* data;
};
class Cosmology {
private:
static const double c = 299792458.0, Mpc2Km = 3.08567758e+19, Yrs2Sec = 3.15569e7;
double H0 = 67.77, OmegaM = (0.022161+0.11889)/(H0*H0), OmegaL = 0.6914, OmegaG = 8.24e-5, OmegaK = 0.0009;
double Ez(double z);
double Hz(double z, void* params);
static double CCallback(double z,void* param)
{
CCallbackHolder* h = static_cast<CCallbackHolder*>(param);
return h->cls->Hz(h->data);
}
public:
double distH, timeH;
Cosmology();
Cosmology(double);
Cosmology(double , double );
Cosmology(double , double , double );
Cosmology(double , double , double , double );
Cosmology(double , double , double , double , double );
double distC(double);
} cosmo;
Cosmology.cpp
#include <cmath>
#include <gsl/gsl_integration.h>
#include "Cosmology.h"
#include<iostream>
using namespace std;
double Cosmology::Hz(double z, void* params) {
double result = 1.0/pow(OmegaL + pow(1.0+z,3.0)*OmegaM + pow(1.0+z,4.0)*OmegaG + pow(1.0+z,2.0)*OmegaK, 0.5);
return result;
}
double Cosmology::distC(double z) {
double lower_limit = 0.0, abs_error = 1.0e-8, rel_error = 1.0e-8, alpha = 0.0, result, error;
gsl_integration_workspace *work_ptr = gsl_integration_workspace_alloc(1000);
gsl_function Hz_function;
void* params_ptr = α
Hz_function.function = &Cosmology::CCallback;
Hz_function.params = params_ptr;
gsl_integration_qags(&Hz_function, lower_limit, z, abs_error, rel_error, 1000, work_ptr, &result, &error);
return distH*result;
}
using namespace std;
int main () {
Cosmology cosmo;
cout << "Comoving Distance: " << cosmo.distC (0.3);
return 0;
}
I am getting the following errors when I tried to compile the code:
Cosmology.h:10: error: ISO C++ forbids declaration of ‘Cosmology’ with no type
Cosmology.h:10: error: expected ‘;’ before ‘*’ token
Cosmology.h:16: error: ISO C++ forbids declaration of ‘constexpr’ with no type
Cosmology.h:16: error: expected ‘;’ before ‘double’
Cosmology.h:17: error: ISO C++ forbids declaration of ‘constexpr’ with no type
Cosmology.h:17: error: expected ‘;’ before ‘double’
In file included from Universe.cpp:3:
Cosmology.h: In static member function ‘static double Cosmology::CCallback(double, void*)’:
by compiling with this line : g++ -Wall -pedantic Cosmology.cpp -o Cosmology std=c++0x
. How could I fix the code?