C++Talk.NET Forum Index C++Talk.NET
C++ language newsgroups
 
Archives   FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

random number generators

 
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated)
View previous topic :: View next topic  
Author Message
francesco
Guest





PostPosted: Fri Feb 03, 2006 4:00 pm    Post subject: random number generators Reply with quote



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::ClassUsingNormalDistribution()
{
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_generator@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(void)"
(?GenerateRndNumbers@ClassUsingNormalDistribution@@QAEXXZ)
1>D:\3.9G\normal_distribution\Debug\normal_distribution.exe : fatal
error LNK1120: 2 unresolved externals

I don't know how to solve the problem. Can anyone help?

Thanks & regards
Cesco


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Allan W
Guest





PostPosted: Sat Feb 04, 2006 5:01 am    Post subject: Re: random number generators Reply with quote



francesco wrote:
Quote:
Hi I have a problem in using the using the boost library for generating
random numbers with a normal distribution.
[snip]
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_generator@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(void)"
(?GenerateRndNumbers@ClassUsingNormalDistribution@@QAEXXZ)
1>D:\3.9G\normal_distribution\Debug\normal_distribution.exe : fatal
error LNK1120: 2 unresolved externals

I don't know how to solve the problem. Can anyone help?

You have to learn how to interpret these error messages.

Here's the first error message, parsed:

ClassUsingNormalDistribution.obj : This is where the error was
detected. It wasn't found during
the compile, but only during the
link.

error LNK2019: This is the error number.

unresolved external symbol This is the description of the
error. It's followed by the name of
the symbol that was missing:

"public: It's a public member function

class boost::variate_generator< This is the return type of the
class boost::rand48, function. Note that every class
class boost::normal_distribution< name has the word "class" in
double> > front.

__thiscall This is how the function gets
called. You can ignore it.

NormalDistribution:: This is the name of the class
where the member is declared.

mVariate( This is the name of the function.

class boost::rand48, First parameter

class boost:: Second parameter
normal_distribution<double>

)" That was the last parameter

(?mVariate@NormalDistribution@@Q This is the "decorated name", also
AE?AV?$variate_generator@Vrand48 known as the "mangled name" of the
@boost@@V?$normal_distribution@N function. Ignore this.
@2@@boost@@Vrand48@3@V?$normal_
distribution@N@3@@Z)

referenced in function Where did we call this function

"public: __thiscall Called from another member function

NormalDistribution:: In this class

NormalDistribution( The name of the function that calls
the missing function -- this is a
constructor.

unsigned __int64, The three parameters of the
double, constructor
double)"

(??0NormalDistribution@@QAE@_KNN@Z) The decorated name. Ignore.

So, the first error says that the constructor
NormalDistribution::NormalDistribution(SeedType,double,double)
called member function
NormalDistribution::mVariate(EngineType, DistributionType)
which you declared but didn't define.


Similarly, the second error says that you also called member function
NormalDistribution::mVariate()
which you also declared but didn't define.

(The two undefined functions are the ones declared just before
the "private" keyword in class NormalDistribution.)

Hope this helps.


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
francesco
Guest





PostPosted: Sat Feb 04, 2006 8:00 pm    Post subject: Re: random number generators Reply with quote



I solved the problem with this code:

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)
: mVariate(EngineType(), DistributionType(mean, std))
{
}
VariateGeneratorType mVariate;

};

The problem was that I had declared them as member of the class
NormalDistribution while they are part of the boost library.

I deeply thank you anyway for the very clear "lecture" about the
interpretation of those link error messages that once were quite
cryptic for me.

Best regards
Francesco


[ See http://www.gotw.ca/resources/clcm.htm for info about ]
[ comp.lang.c++.moderated. First time posters: Do this! ]
Back to top
Display posts from previous:   
Post new topic   Reply to topic    C++Talk.NET Forum Index -> C++ Language (Moderated) All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2006 phpBB Group
SEO toolkit © 2004-2006 webmedic.