Static members sometimes confuse me. I understand how to initialize a simple built-in type, for example int , with something next to int myClass::statVar = 10; which you put in the .cpp file, but I have something like the following:
class myClass { public:
The basic idea is quite simple: myClass needs access to a random generator for one of its member functions. I can also have only a few instances of the generator, since each object is quite large. However, the type of RandomGenerator must be “initialized”, so to speak, by calling RandomGenerator::Randomize() , which the compiler will not allow you to do, since it is not a constant value (is this correct?).
So how can I do this job?
Or maybe I should not use a static variable in this case and do it differently?
source share