Boost logo

Boost :

Subject: Re: [boost] [random] example code fails inside struct
From: Gevorg Voskanyan (v_gevorg_at_[hidden])
Date: 2011-04-16 08:32:13


Beman Dawes wrote:
> > You can't initialize a class data member like that.
> > boost::uniform_int<> million(1,1000000); is valid in a function body or in
> > namespace-scope, but not in class scope...
>
> Doesn't that create a usage problem because there aren't alternative
> constructors that do work at class scope?

What do you mean? If I guess what you're asking here correctly, then that is a
limitation in C++03 addressed in C++11. Here's the proposal for
that: http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2008/n2756.htm
It still won't make the code to compile as you have written it, but with slight
changes it will:

struct X
  {
    boost::mt19937 rng;
    boost::uniform_int<> million{1,1000000}; // or million
= boost::uniform_int<>(1, 1000000);
    boost::variate_generator<boost::mt19937&, boost::uniform_int<> >
            random_value{rng, million};
  };

Please let me know if that info wasn't what you were looking for.

HTH,
Gevorg


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk