C++ Syntax for accessing operator () from a pointer to an object -
i have instance of c++ 11 random number distribution; uniform_int_distribution, , instance of c++ m19937_64 algorithm.
i passing references these using pointers class maintains pointer these 2 objects later use.
in member function of class, wish call operator() function generate random number uniform_int_distribution.
i have done following. (may incorrect, hence question.)
std::random_device rd; std::mt19937_64 gen(rd()); std::mt19937_64 *gen_p = &gen; std::uniform_int_distribution<int> dis(0, 9); std::uniform_int_distribution<int> *dis_p = &dis; then following: (later in code, within class member function.)
int random_number = (*dis_p)(*gen_p); this looks bit strange or ambiguous, or @ least me since i've not encountered before.
without pointers, 1 following:
int random_number = dis(gen_p);
use either
(*dis_p)(*gen_p); (as are) or
dis_p->operator()(*gen_p); personally, however, not use pointers @ all. instead
dis(gen); will trick (since dis_p points @ dis , gen_p points @ gen).
it possible store references in class (albeit need initialised using constructor, , cannot reseated pointers can).
Comments
Post a Comment