Jump to content
  • Advertisement
Sign in to follow this  
Drakkcon

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

This topic is 4855 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!