dereference a pointer to a template classes operator

HI all,

I'm using the boost::random library.

It has a template class variate_generator which overloads the () operator.

It is used as follows:

// random engine, distribution
boost::variate_generator<boost::mt19937&, boost::uniform_int<> > die(rng, six);
// rng and six have been defined earlier

//we can now use the overloaded operator () to draw a number:
int x = die();


MY PROBLEM:

I need to hold an instance of class variate_generator and regularly draw numbers.

I use a pointer to the class:

boost::variate_generator<boost::mt19937&, boost::uniform_int<> > *pDie;

pDie=new boost::variate_generator<boost::mt19937&, boost::uniform_int<> >(rng, six);

I do not know how to use the overloaded () operator
this->pDie->() //this is garbage - but how to do it correctly?


My intermediate solution is to add a member function 'get' which does the same as the overloaded operator, therefore:

this->pDie->get();

works. But I dislike to edit the libraries code.


thx
Alex
Hi Alex,
If I understand correctly,
(*(this->pDie))()
should do it.
first, the pointer is obtained from "this" (unnecessary by the way...you can just use pDie inside the class).
second, the pointer is dereferenced to give you the object it is pointing to.
last, you access the function call overload for the object.
(*pDie)();

or the uglier

pDie->operator()();
Hi,
it works, thank you!
sorry for the late answer....

Alex
Topic archived. No new replies allowed.