I'd like to define my objects of boost-distributions in my class and keep on using them.
For the binomial Distribution this was no problem.
Bdist.hpp
#include "boost/math/distributions/binomial.hpp"
class Bdist {
public:
Bdist();
Bdist(unsigned n, double theta);
virtual ~Bdist(){};
/**stuff**/
private:
boost::math::binomial_distribution<> binomialboost;
double theta; //Every experiment successes with this propability
unsigned n; //Amount of trials
};
And in the Bdist.cpp
Bdist::Bdist(unsigned n, double theta) :
n(n), theta(theta) {
binomialboost= boost::math::binomial_distribution<> (((int)n),theta);
}
Bdist::Bdist() {
n = 0;
theta = 0.0;
binomialboost = boost::math::binomial_distribution<>(((int)n), theta);
}
Strangely, when I do the same with the geometrical distribution it fails:
Gdist::Gdist() {
theta = 0;
geometricboost = boost::math::geometric_distribution<>(theta);
}
Gdist::Gdist(double theta) :
theta(theta) {
geometricboost = boost::math::geometric_distribution<>(theta);
}
Here's the Gdist.hpp
#include <complex>
#include <boost/math/distributions/geometric.hpp>
class Gdist {
public:
Gdist();
Gdist(double theta);
virtual ~Gdist(){};
/**stuff**/
private:
boost::math::geometric_distribution <> geometricboost;
double theta; //Propability
};
For testing purposes, I wrote a small main.cpp to see how it would react with different initialisations:
#include <cstdlib>
#include <boost/math/distributions/geometric.hpp>
int main(int argc, char** argv) {
boost::math::geometric_distribution<> geoboost; //fails here
geoboost = boost::math::geometric_distribution<double>(0.1);
printf("%f",boost::math::pdf(geoboost, 0.5));
return 0;
}
Here I get:
main.cpp:18:39: error: no matching function for call to ‘boost::math::geometric_distribution<double>::geometric_distribution()’
boost::math::geometric_distribution<> geoboost;
^
By inserting double for the template...
boost::math::geometric_distribution<double> geoboost; //Error still here
geoboost = boost::math::geometric_distribution<double>(0.1);
The message doesn't get better:
main.cpp:18:45: error: no matching function for call to ‘boost::math::geometric_distribution<double>::geometric_distribution()’
boost::math::geometric_distribution<double> geoboost;
^
The definitions of binomial_distribution and geometric_distribution aren't so different at all:
template <class RealType = double, class Policy = policies::policy<> >
class binomial_distribution
{
public:
typedef RealType value_type;
typedef Policy policy_type;
binomial_distribution(RealType n = 1, RealType p = 0.5) : m_n(n), m_p(p)
And
template <class RealType = double, class Policy = policies::policy<> >
class geometric_distribution
{
public:
typedef RealType value_type;
typedef Policy policy_type;
geometric_distribution(RealType p) : m_p(p)
How can this be? Why is one failing and the other one not?