I have a c++ project with several classes, which all require rng. For this purpose I use the following bit of code, in a header that all classes include.
Random.h :
#include <random>
#include <functional>
std::default_random_engine generator;
std::uniform_real_distribution<float> Udistribution(0.0f, 1.0f);
std::normal_distribution<float> Ndistribution(0.0, 1.0);
auto uniform01 = std::bind(Udistribution, generator);
auto normal01 = std::bind(Ndistribution, generator);
A.h :
#include "Random.h"
...
B.h :
#include "Random.h"
...
But it throws a bunch of linker error on compilation. I have tried to use the extern keyword, but the std::bind messes things up: I can't use auto anymore, and I have to figure out the types of uniform01 and normal01. I came up with the following, which triggers intellisense error : incompatible declarations.
new A.h:
#include "Random.h"
extern std::_Binder<std::_Unforced, const std::uniform_real_distribution<float>&, const std::default_random_engine&> uniform01;
extern std::_Binder<std::_Unforced, const std::normal_distribution<float>&, const std::default_random_engine&> normal01;
Replacing uniform01 with uniform01() does not change anything. Does anyone know what the extern declaration should look like ?