LNK2001 代码错误
我收到 LNK2001 错误。代码已包含在下面。有人可以帮我吗?
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"
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"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
看来您缺少 actionTaken 的定义(类中的声明不够)。是否添加
ActionTakenVector InstrumentCache::actionTaken;
在 PerformanceTest.cpp 有帮助吗?
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?
静态成员需要初始化。在类之外的某个地方,您应该编写
ActionTakenVector InstrumentCache::actionTaken
,它应该初始化该静态字段并消除您的错误。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.