0

I'm a new C++ developer but have programmed before in easier languages. I'm trying to use a vector in a script and I don't understand this error to the point where I don't really know what to do to debug the error. I do so similar postings about LNK2019 and vectors but none of the other answers seem to apply to this problem. Since I'm just learning there could be something fundamentally wrong with my understanding of C++ and vectors.

error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: struct SDL_Rect & __thiscall std::vector >::operator[](unsigned int)" (??A?$vector@USDL_Rect@@V?$allocator@USDL_Rect@@@std@@@std@@QAEAAUSDL_Rect@@I@Z)

I instantiate the std::vector in my header file SpriteSheet.h:

#pragma once
#include <SDL.h>
#include <SDL_image.h>
#include <stdio.h>
#include <vector>
class SpriteSheet {
public:
    SpriteSheet(SDL_Texture* texture); //Defines a SpriteSheet from the file location.
    ~SpriteSheet();
    void free();
    int getWidth();
    int getHeight();
    SDL_Texture* getTexture();
    void defineSprite(int StartX, int StartY, int sizeX, int sizeY, int spriteID);
    void renderSprite(SDL_Renderer* renderer, int spriteID, SDL_Rect* destR);
private:
    SDL_Texture* texture; //Sheet texture
    //Dimensions
    int width;
    int height;
    std::vector<SDL_Rect*> sprites;
};

SpriteSheet.cpp:

#include "SpriteSheet.h"
SpriteSheet::SpriteSheet(SDL_Texture* texture) {
    this->texture = texture;
}

SpriteSheet::~SpriteSheet() {
}

void SpriteSheet::defineSprite(int StartX, int StartY, int sizeX, int sizeY,     int spriteID) {
    SDL_Rect* spriteRect = new SDL_Rect;
    spriteRect->x = StartX;
    spriteRect->y = StartY;
    spriteRect->w = sizeX;
    spriteRect->h = sizeY;
    sprites[spriteID] = spriteRect;
}

void SpriteSheet::free() {
    if (texture != NULL) {
        SDL_DestroyTexture(texture);
        texture = NULL;
        width = 0;
        height = 0;
    }
}

void SpriteSheet::renderSprite(SDL_Renderer* renderer, int spriteID, SDL_Rect* destR) {
    SDL_RenderCopy(renderer, texture, sprites[spriteID], destR);
}

int SpriteSheet::getWidth() {
    return width;
}

SDL_Texture* SpriteSheet::getTexture() {
    return texture;
}

int SpriteSheet::getHeight() {
    return height;
}

I've narrowed it down and the error seems to be occurring in the SpriteSheet.cpp file on the line that says "sprites[spriteID] = spriteRect;"

EDIT: Problem is now fixed. If you are using Visual Studio Express go to

Project->(Project) Properties->C/C++->Preprocessor

Edit the Preprocessor definitions and remove _DEBUG from the list of definitions. Then Press OK and you should be good!

deery50
  • 65
  • 1
  • 5
  • https://social.msdn.microsoft.com/Forums/vstudio/en-US/5e126c79-77f3-4d50-a47f-a9ce35cff0a4/unresolved-external-symbol-impcrtdbgreportw – Severin Pappadeux Jul 13 '15 at 01:08
  • And it would be useful to add tags `visual-c++` and `visual-studio-20xx` where xx is the year of what you're using – Severin Pappadeux Jul 13 '15 at 01:10
  • The error is a linker error, not a compiler error or runtime error. You are not linking the required libraries, in other words, your linker project settings are not correct. `I'm trying to use a vector in a script` When you use a compiled language, you are not writing a "script". You are writing a program that will be compiled to object code and the object code is linked together to create the final executable. – PaulMcKenzie Jul 13 '15 at 01:10
  • @Severin Thanks, I removed the DEBUG_ from the Preprocessor Definitions and now it will start running the application but breaks on the "sprites[spriteID] = spriteRect" line with an access violation. In the future i will write posts with my visual studio year, i'm using 2013. – deery50 Jul 13 '15 at 01:18
  • Nevermind I now understand the problem, thanks for all the help! – deery50 Jul 13 '15 at 01:27

0 Answers0