LNK2001代码错误

时间:2010-03-18 15:25:09

标签: c++ linker-errors 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"

2 个答案:

答案 0 :(得分:2)

需要初始化静态成员。在课堂外的某个地方,你应该写ActionTakenVector InstrumentCache::actionTaken,它应该初始化那个静态字段并消除你的错误。

答案 1 :(得分:2)

似乎你缺少actionTaken的定义(类中的声明是不够的)。是否添加

ActionTakenVector InstrumentCache :: actionTaken;

在PerformanceTest.cpp帮助中