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!