class basics

Hi ! I'm trying to build a class that will use the std::tr1::lognormal_distribution class but I'm having trouble putting it all together in my new class...how should it be done ?
Thanks !

1
2
3
4
5
6
7
8
9
10
11
CSleeper::CSleeper(double m, double sd)
{
	default_random_engine generator(ULONG(time(0)));	//random seed
	lognormal_distribution<double> distribution(m, sd);     //set the dist params
}

void CSleeper::Sleep(int outlay)
{
	int x = distribution(generator); //error 'distribution' and 'generator' unidentified
//...
}
Make generator and distribution members of CSleeper, and initialize them in the constructor initialization list.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
class CSleeper
{
public:
	CSleeper(double m, double sd);
	void Sleep(int outlay);
private:
	std::default_random_engine generator;
	std::lognormal_distribution<double> distribution;
};

CSleeper::CSleeper(double m, double sd)
:	generator(ULONG(time(0))),
	distribution(m, sd)
{
}
Thanks Peter :D
Topic archived. No new replies allowed.