mercredi 6 janvier 2016

Initialize random constant values in ctor

In my class there appeared necessity to initialize some constant random values in sructure.

To achieve this there are defined limits:

std::random_device rd;
std::mt19937 eng(rd());
std::uniform_int_distribution<> lim1(3, 6);
std::uniform_int_distribution<> lim2(7, 20);
std::uniform_int_distribution<> lim3(1000, 100000);

And following structure:

typedef struct {
    unsigned        c1, c2, c3;
    const unsigned  limc1 = lim1(eng), 
                    limc2 = lim2(eng), 
                    limc3 = lim3(eng);
} CTR;

So, when I try to do some initialization with these values

class Foo {
    private:
        CTR ctr;
    public:
    voud initializeCTR(CTR &ctr);
};

The problem is that field ctr invisible for initializeCTR()

Foo foo;
foo.initializeCTR(ctr); <- ctr undefined here

How should I code ctor or something other to achieve different random values for all class instances?

Aucun commentaire:

Enregistrer un commentaire