views:

58

answers:

2

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"
+2  A: 

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.

Dathan
Thanks so much it fixed the problem
aajkaltak
+2  A: 

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?

xqib-team
Oh, right - defined, not initialized. Well, initialized, too. Hard to keep terminology straight sometimes.
Dathan