Link error using std::vector

天大地大妈咪最大 提交于 2019-12-13 03:37:59

问题



I'm having a problem with a vector declaration.
Here's the code:

.h

#ifndef ANIMATEDSPRITE_H_
#define ANIMATEDSPRITE_H_

#include "Sprite.h"
#include <vector>

//using namespace std;

class AnimatedSprite //abstract class to point sprites
{
public:
    AnimatedSprite();
    ~AnimatedSprite();

    //gets and sets
    Sprite GetMySprite(int _index);
    void SetSpriteToList(Sprite _sprite);
    int GetState() const;
    void SetState(int _state);

    //other



private:
    std::vector<Sprite> spriteList;

    int state; //estado que esse sprite representa (parado esquerda, andando direita, etc)
};

#endif

.cpp

#include "AnimatedSprite.h"

AnimatedSprite::AnimatedSprite()
{
    spriteList.clear();
    state = NULL;
}

AnimatedSprite::~AnimatedSprite()
{

}

Sprite AnimatedSprite::GetMySprite(int _index)
{
    return spriteList[_index];
}

void AnimatedSprite::SetSpriteToList( Sprite _sprite )
{
    //Sprite* temp = new Sprite(1,2);
    spriteList.push_back(_sprite);
}

int AnimatedSprite::GetState() const
{
    return state;
}

void AnimatedSprite::SetState( int _state )
{
    state = _state;
}

But I'm getting 2 errors:

Error 1 error LNK2019: unresolved external symbol imp_CrtDbgReportW referenced in function "public: class Sprite & __thiscall std::vector >::operator[](unsigned int)" (??A?$vector@VSprite@@V?$allocator@VSprite@@@std@@@std@@QAEAAVSprite@@I@Z) AnimatedSprite.obj

Error 2 fatal error LNK1120: 1 unresolved externals C:\DevProjects\SDLSkeleton\Debug\SDLSkeleton.exe

I've found a solution removing the _DEBUG from the Preprocessor Definitions, but it seems kinda wrong to do that.
Is it the right solution? What's the consequence of removing it?
In the book and documentations I've checked it should be just a common variable declaration, but this errors showed up.

Thanks.


回答1:


This is because your build is inconsistent: you define _DEBUG macro, but link with release CRT version (/MD). So either remove _DEBUG, or select /MDd option.



来源:https://stackoverflow.com/questions/10401150/link-error-using-stdvector

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!