Hi I have a problem in using the using the boost library for generating
random numbers with a normal distribution.
I created the following files and classes:
#ifndef __NORMALDISTRIBUTION_H
#define __NORMALDISTRIBUTION_H
#include <boost/random.hpp>
using namespace std;
class NormalDistribution {
public:
typedef boost::rand48 EngineType;
typedef boost::normal_distribution<> DistributionType;
typedef boost::uint64_t SeedType;
typedef boost::variate_generator<EngineType, DistributionType>
VariateGeneratorType;
NormalDistribution(SeedType s, double mean, double std)
: mSeed(s)
{
DistributionType distribution(mean, std);
mDistribution = distribution;
mEngine.seed(mSeed);
mVariate(mEngine, mDistribution);
}
VariateGeneratorType::result_type mVariate();
VariateGeneratorType mVariate(EngineType, DistributionType);
private:
SeedType mSeed;
EngineType mEngine;
DistributionType mDistribution;
};
#endif //__NORMALDISTRIBUTION_H
//------------------
// ClassUsingNormalDistribution.h
//------------------
#ifndef __CLASSUSINGNORMALDISTRIBUTION_H
#define __CLASSUSINGNORMALDISTRIBUTION_H
#include "NormalDistribution.h"
class ClassUsingNormalDistribution {
public:
ClassUsingNormalDistribution();
~ClassUsingNormalDistribution() {}
void GenerateRndNumbers();
private:
NormalDistribution* mpNormDis;
};
#endif //__CLASSUSINGNORMALDISTRIBUTION_H
//------------------
// ClassUsingNormalDistribution.cpp
//------------------
#include<iostream>
using namespace std;
#include "ClassUsingNormalDistribution.h"
ClassUsingNormalDistribution::ClassUsingNormalDist ribution()
{
mpNormDis = new NormalDistribution(0u, 0.0, 1.0);
}
void ClassUsingNormalDistribution::GenerateRndNumbers()
{
cout << mpNormDis->mVariate() << endl;
}
//------------------
// Main.cpp
//------------------
#include "ClassUsingNormalDistribution.h"
int main() {
ClassUsingNormalDistribution normDistObj;
for (int i = 0; i < 10; ++i)
normDistObj.GenerateRndNumbers();
}
---------------------------------------
and I get the following link errors:
1>ClassUsingNormalDistribution.obj : error LNK2019: unresolved external
symbol "public: class boost::variate_generator<class
boost::rand48,class boost::normal_distribution<double> > __thiscall
NormalDistribution::mVariate(class boost::rand48,class
boost::normal_distribution<double>)"
(?mVariate@NormalDistribution@@QAE?AV?$variate_gen erator@Vrand48@boost@@V?$normal_distribution@N@2@@ boost@@Vrand48@3@V?$normal_distribution@N@3@@Z)
referenced in function "public: __thiscall
NormalDistribution::NormalDistribution(unsigned __int64,double,double)"
(??0NormalDistribution@@QAE@_KNN@Z)
1>ClassUsingNormalDistribution.obj : error LNK2019: unresolved external
symbol "public: double __thiscall NormalDistribution::mVariate(void)"
(?mVariate@NormalDistribution@@QAENXZ) referenced in function "public:
void __thiscall ClassUsingNormalDistribution::GenerateRndNumbers(v oid)"
(?GenerateRndNumbers@ClassUsingNormalDistribution@ @QAEXXZ)
1>D:\3.9G\normal_distribution\Debug\normal_distrib ution.exe : fatal
error LNK1120: 2 unresolved externals
I don't know how to solve the problem. Can anyone help?
Thanks & regards
Cesco