Boost logo

Boost :

Subject: Re: [boost] [random] example code fails inside struct
From: Beman Dawes (bdawes_at_[hidden])
Date: 2011-04-16 07:12:49


On Sat, Apr 16, 2011 at 6:54 AM, Gevorg Voskanyan <v_gevorg_at_[hidden]> wrote:
> Beman Dawes wrote:
>>   struct X
>>   {
>>     boost::mt19937 rng;
>>      boost::uniform_int<> million(1,1000000);  // VC++ 10 error  C2059:
>> syntax error : 'constant'
>>      boost::variate_generator<boost::mt19937&, boost::uniform_int<>  >
>>              random_value(rng,  million);
>>   };
>>
>> Why does the example code from the docs fail to  compile when placed
>> inside a struct or class? What am I  missing?
>
>
> 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?

--Beman


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