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:
开发者_StackOverflow中文版 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"
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?
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.
精彩评论