static CArray C++ MFC [duplicate]

  c++, mfc

I simply cannot seem to be able to make a static CArray and work with it.

Here’s my code:

class WhiteBoard
{
public:

    static CArray<WhiteBoard, WhiteBoard> test;

    void tester()
    {
        test.Add(*this);
    }
};

And upon calling the tester method, I get an unresolved external symbol.
Full error code is:

Severity    Code    Description Project File    Line    Suppression State
Error   LNK2001 unresolved external symbol "public: static class CArray<class WhiteBoard,class WhiteBoard> WhiteBoard::test" ([email protected]@@[email protected]@@[email protected]@@A) MFCApplication2 C:Userssw.engsourcereposMFCApplication2MFCApplication2Dlg.obj 1   

This is my first time working with CArray but I messed around with CArray of int and all worked alright.

Could it be that I’m trying to have a CArray of WhiteBoard inside of WhiteBoard? (I do need this functionality to keep track of all child objects made, which is why I do it)

Removing the static keyword makes everything run. But then it’s not a static member, and I need it to be one.

Anyways, all help would be incredible and very much appreciated.

EDIT 1:

I’ve made another class which I called BoardBoss.
WhiteBoard inherits BoardBoss.
CArray is now of BoardBoss type. CArray<BoardBoss, BoardBoss> test;

The issue persists.

Source: Windows Questions C++

LEAVE A COMMENT