mardi 18 septembre 2018

Declaring an object of random class in class definition

So, I am writing a class in which I need to generate random numbers sampled from a uniform distribution. Since I need to generate random numbers frequently I want to create an object inside the class definition.

Here is the example of what I am trying to accomplish. "example.h"

class ABC
{
  public:
   ABC();
   /* code goes here */
  private:
   std::random_device rd;
   std::mt19937 mt(rd());
   std::uniform_int_distribution<int> dist;
}

"example.cpp"

ABC::ABC():ABC::dist(0,12)
{
  /* ABC class constructor */
}

The above code doesn't compile. Can anyone help or point out the mistake. Thanks in advance.

Aucun commentaire:

Enregistrer un commentaire