I use VC 2010 and try to keep the overhead and duplicate codes of some functions low by putting random definitions in the constructor of each instance of the class, and then calling from there if necessary. I have now simplified:
#include <random> #include <Windows.h> mt19937 eng(GetTickCount()); class Cycles { int line; normal_distribution<> rand_norm; variate_generator<mt19937&,normal_distribution<>> r_norm; public: Cycles() : rand_norm(0.85,0.05), r_norm(eng,rand_norm) { line=0; } }
Unfortunately, this does not work, and I get this error:
\ vc \ include \ random (513): error C2248: 'std :: tr1 :: _ Ewrap <_Engine, _Tgt_type> :: operator =': cannot access the private member declared in the class' std :: tr1: : _ Ewrap <_Engine, _Tgt_type> '
\ vc \ include \ random (446): see the declaration 'std :: tr1 :: _ Ewrap <_Engine, _Tgt_type> :: operator ='
This diagnostic occurred in the function generated by the compiler: std :: tr1 :: variate_generator <_Engine, _Distrib> & std :: tr1 :: variate_generator <_Engine, _Distrib> :: operator = (const std :: tr1 :: variate_generator <_Engine, _Distrib > &) '
I understand that they must be initialized before the constructor is opened, otherwise these are errors due to the lack of a default constructor, but I do not understand why this fails. My C ++ fu is pretty rusty.
Each example that I saw shows that the distributor and generator are initialized globally or locally in a function that calls it, which seems silly to me, because I have several member functions that will use r_norm, called in a closed loop. It is bad copes with the smell. Doesn't anyone know what I'm missing?