简体   繁体   中英

LNK2001 error in code

I am getting LNK2001 error. The code has been included below. Can someone please help me out?

Error   3   error LNK2001: unresolved external symbol "private: static class   std::vector<struct _UpdateAction,class std::allocator<struct _UpdateAction> > InstrumentCache::actionTaken" (?actionTaken@InstrumentCache@@0V?$vector@U_UpdateAction@@V?$allocator@U_UpdateAction@@@std@@@std@@A)    PerformanceTest.obj 

//UpdateAction.h

typedef struct _UpdateAction
{
    enum FIS_ACTION {
        ADDED,
        UPDATED,
        DELETED
    };
    int id;
    int type;
    int legacyType;
    FIS_ACTION action;

}UpdateAction;

typedef std::vector<UpdateAction> ActionTakenVector;

// InstrumentCache.h

#include UpdateAction.h

class InstrumentCache
{
public:
    static ActionTakenVector& GetApplicationUpdateVector ()
    {
    return actionTaken;
    }

    static void ClearApplicationUpdateVector()
    {
        actionTaken.clear();
    }
private:
    static ActionTakenVector actionTaken;
};

//fisClient.h

#include "UpdateAction.h"
#include "InstrumentCache.h"

class FISClient
{
    void FunctionOne()
    {
        ActionTakenVector& rV = InstrumentCache::GetApplicationUpdateVector();
        InstrumentCache::ClearApplicationUpdateVector();
    }
} ;

PerformanceTest.cpp

#include "fisClient.h"

Static members need to be initialized. Somewhere outside your class, you should write ActionTakenVector InstrumentCache::actionTaken , which should initialize that static field and get rid of your error.

It seems that you are missing the definition of actionTaken (the declaration in the class is not enough). Does adding

ActionTakenVector InstrumentCache::actionTaken;

in PerformanceTest.cpp help?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM