Boost logo

Boost Users :

Subject: [Boost-users] How can I use random library in a class? Can any one with kindness help me?
From: fmingu (fmingu_at_[hidden])
Date: 2010-05-11 01:41:00


How can I use random library in a class? Can any one with kindness help me?
 
I am using boost(version boost_1_37_0) random library in Dev-C++ with gcc.
and the code is:
#include "boost/random/normal_distribution.hpp"
#include <boost/random.hpp>
.................................
class TransferedSignal{
 public:
       TransferedSignal(){
              one(0.0,1.0) ;
              die(rng, one);
        };
        
        double output(){
               return die();
        };
private:
        boost::mt19937 rng;
        boost::uniform_real<> one;
        boost::variate_generator<boost::mt19937&, boost::uniform_real<> > die;
};

int main(int argc, char *argv[])
{
 TransferedSignal transferedsignal();
 for (int i=0; i<100;i++) transferedsignal.output();
 
 system("PAUSE");
  return 0;
}
 
But the complier told me that:
mainprojectme13.cpp: In constructor 'TransferedSignal::TransferedSignal()':
mainprojectme13.cpp:154: error: no matching function for call to 'boost::variate_generator<boost::mt19937&, boost::uniform_real<double> >::variate_generator()'
F:/CB2009/boost_1_37_0/boost/random/variate_generator.hpp:97: note: candidates are: boost::variate_generator<Engine, Distribution>::variate_generator(Engine, Distribution) [with Engine = boost::mt19937&, Distribution = boost::uniform_real<double>]
F:/CB2009/boost_1_37_0/boost/random/variate_generator.hpp:87: note: boost::variate_generator<boost::mt19937&, boost::uniform_real<double> >::variate_generator(const boost::variate_generator<boost::mt19937&, boost::uniform_real<double> >&)
mainprojectme13.cpp:155: error: no match for call to '(boost::uniform_real<double>) (double, double)'
mainprojectme13.cpp:156: error: no match for call to '(boost::variate_generator<boost::mt19937&, boost::uniform_real<double> >) (boost::mt19937&, boost::uniform_real<double>&)'
F:/CB2009/boost_1_37_0/boost/random/variate_generator.hpp:100: note: candidates are: typename Distribution::result_type boost::variate_generator<Engine, Distribution>::operator()() [with Engine = boost::mt19937&, Distribution = boost::uniform_real<double>]
mainprojectme13.cpp: In function 'int main(int, char**)':
mainprojectme13.cpp:173: error: request for member 'output' in 'transferedsignal', which is of non-class type 'TransferedSignal()'
 
And I do not know how to solve it.
Shauld I define "boost::variate_generator<Engine, Distribution>::variate_generator() " in the random library?
 
But God knows what will be happened after that.
Can any one with kindness help me?
Thanks a lot.
 
 



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net