LNK2001 代码错误

发布于 2024-08-25 19:47:50 字数 1431 浏览 6 评论 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 

//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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

半城柳色半声笛 2024-09-01 19:47:50

看来您缺少 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?

谎言月老 2024-09-01 19:47:50

静态成员需要初始化。在类之外的某个地方,您应该编写 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文