I defined the following structure to be used across the application by several classes.
ZHTypes.h
#ifndef ZHTypes_h
#define ZHTypes_h
struct BeingHitParams
{
bool isApplyKnockBack=true;
};
BeingHitParams *default_BeingHitParams_ptr = new BeingHitParams();
#endif
I defined a following variable
default_BeingHitParams_ptr
for the case the I will use it in several places for default parameters of function as I don't need to create a new structure all the time.
Anyway, the above defined variable produces linking error whenever I refer to it in the code inside a class. But if I add static in front then it works fine.
static BeingHitParams *default_BeingHitParams_ptr = new BeingHitParams();
So my question is why can't we access global but non-static variable from within a class? I also want to know additional explanation of why C++ is restricted in accessing variable like in the situation above.