Sign in to follow this  
Drakkcon

I can't figure out why I'm getting this linker error

Recommended Posts

class InstructionList
{
    static std::vector<Instruction*> instructions;
        
    public:
        static void Add(Instruction* instr_) 
        {
            instr_->Initialize();
             nstructions.push_back(instr_);
        }
};
The error is: main.o(.text$_ZN7stratus15InstructionList3AddEPNS_11InstructionE[stratus::InstructionList::Add(stratus::Instruction*)]+0x29): In function `ZNSt6vectorIPN7stratus11InstructionESaIS2_EE3endEv': C:/Dev-Cpp/Bin/../lib/gcc/mingw32/3.4.2/../../../../include/c++/3.4.2/bits/stl_iterator.h: undefined reference to `stratus::InstructionList::instructions' collect2: ld returned 1 exit status I'm using MinGW. Thanks for any help.

Share this post


Link to post
Share on other sites
It's been a while but i think you have to give the static member some presence.

class InstructionList

{

static std::vector<Instruction*> instructions;



public:

static void Add(Instruction* instr_)

{

instr_->Initialize();

nstructions.push_back(instr_);

}

};

static std::vector<Instruction*> InstructionList::instructions;

Something like that.

ace

Share this post


Link to post
Share on other sites
Thanks a lot!

That was it, except you have to remove the second 'static'.
I was practically pounding my head on the keyboard over that one!

Share this post


Link to post
Share on other sites
ace_lovegrove is right, when using static variables inside a class you need to provide a definition of the variable outside of the class in order to use them. Failure to do so will give you an unresolved external error (VS) or undefined reference (GCC/MinGW).

EDIT: too slow.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this