Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

C++ unresolved external symbol (public static int)

Tags:

c++

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++;
    }
}
like image 222
XBoom Avatar asked Jun 06 '17 08:06

XBoom


1 Answers

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.

like image 97
Hatted Rooster Avatar answered Nov 13 '22 23:11

Hatted Rooster