I want to be able to initialise the static member scalingfactor in the following class:
class ScalingRect: public Rect
{
public:
static float scalingfactor;
...
};
I thought I’d initialise it using a static member function of another class like this in the .cpp
float ScalingRect::Rect = Engine::GetScaleFactor();
However, I don’t want to call GetScaleFactor() before the Engine class is ready. How can I ensure it gets called at the right time?
instead of having the static as a class member, make it a static inside a static method, and return a reference to it:
Now on your first call to scalingfactor() should ideally be at the end of the initiliazer for Engine, or as long as you ensure that your first call to scalingfactor() happens after the Engine initializer is completed this should work…