5
votes

When I try to compile this, I get this linker error:

LNK2001 unresolved external symbol "public: static int HooksXD::night" (?night@HooksXD@@2HA)

The header is this:

class HooksXD
{
    public:
        static void XD3();
        static int night;
        static int night2;
};

Variables are public not private because I need to access them from other voids witch are not in the same class.

The cpp file:

HooksXD lmao;
void HooksXD::XD3()
{
    //this void will be called from other cpp files
    lmao.night = 1;
    lmao.night2 = 1;
};

bool __stdcall CreateMoveClient_Hooked(float frametime, CUserCmd* pCmd)
{
    if (lmao.night = 1)
    {
        //some code
        lmao.night++;
    }
}
1
cpp file int HooksXD:: night=0; int HooksXD:: night2=0; Static member are the class member all object of the class access same variable. So we have to define it seprately. - user1438832
As an aside, the line if (lmao.night = 1) is almost certainly wrong, that's an assignment, not a comparison. - Colin

1 Answers

5
votes

You have only declared night and night2, they still need definitions. (because they're static)

In your cpp file :

int HooksXD::night = 0;
int HooksXD::night2 = 0;

And then to access one don't do lmao.night, since it's a static you should access it through the type name : HooksXD::night. Make sure you actually need static here though.