
16 Apr
2011
16 Apr
'11
10:54 a.m.
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. In C++11 I think you could do this however: boost::uniform_int<> million{1,1000000};
--Beman
HTH, Gevorg