繁体   English   中英

使用std :: vector的链接错误

[英]Link error using std::vector


我对向量声明有疑问。
这是代码:

。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;
}

但是我遇到了两个错误:

错误1错误LNK2019:函数“ public:class Sprite&__thiscall std :: vector> :: operator [](unsigned int)”中引用的未解析的外部符号imp _CrtDbgReportW”(?? A?$ vector @ VSprite @@ V?$ allocator @VSprite @@@ std @@@ std @@ QAEAAVSprite @@ I @ Z)AnimatedSprite.obj

错误2致命错误LNK1120:1个未解决的外部C:\\ DevProjects \\ SDLSkeleton \\ Debug \\ SDLSkeleton.exe

我找到了从预处理器定义中删除_DEBUG的解决方案,但是这样做似乎有点错误。
这是正确的解决方案吗? 删除它有什么后果?
在书和文档中,我检查了它应该只是一个普通的变量声明,但是出现了此错误。

谢谢。

这是因为您的版本不一致:您定义了_DEBUG宏,但是链接了CRT版本(/ MD)。 因此,要么删除_DEBUG,要么选择/ MDd选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM