使用std :: vector链接错误 [英] Link error using std::vector

查看:282
本文介绍了使用std :: vector链接错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我遇到了矢量声明的问题。

这是代码:


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

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

但我收到2个错误:

But I'm getting 2 errors:


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

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

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

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

我找到了一个从预处理器定义中删除_DEBUG的解决方案,但这样做似乎有点不对。

这是正确的解决方案吗?删除它的后果是什么?

在我检查过的书和文档中,它应该只是一个常见的变量声明,但是出现了这个错误。

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.

谢谢。

推荐答案

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

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.

这篇关于使用std :: vector链接错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆