0

我收到 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 

//更新动作.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();
    }
} ;

性能测试.cpp

#include "fisClient.h"
4

2 回答 2

2

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

于 2010-03-18T15:32:00.910 回答
2

看来您缺少 actionTaken 的定义(类中的声明是不够的)。是否添加

ActionTakenVector InstrumentCache::actionTaken;

在 PerformanceTest.cpp 有帮助吗?

于 2010-03-18T15:32:04.913 回答