Sprite1 *test = new Sprite1(450, 450, "enemy.bmp", *screen);
test->DrawJon();
SDL_Delay(1000);
test->MoveJon(20,20);
I am getting a runtime error on line #2. It says access violation at 0x0
Sprite1 is a class I have defined and DrawJon() and MoneJon() in the class. This syntax is ok with the compiler but fails in runtime.
Sprite1.cpp
#include "Sprite1.h"
Sprite1::Sprite1(int posX, int posY, std::string imagePath, SDL_Surface screen) : PosX(posX), PosY(posY), ImagePath(imagePath), Screen(screen)
{
void DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen );
void DrawJon();
void MoveJon(int xDist, int yDist);
}
void Sprite1::DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( sprite, NULL, screen, &offset );
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
void Sprite1::DrawJon()
{
#pragma region Char to String Conversion
string ImagePath;
char * writable = new char[ImagePath.size() + 1];
copy(ImagePath.begin(), ImagePath.end(), writable);
writable[ImagePath.size()] = '\0';
#pragma endregion
temp = SDL_LoadBMP(writable);
sprite = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
// free the string after using it
delete[] writable;
DrawSprite1Jon(PosX, PosY, sprite, screen);
}
Sprite1.h
#include <string>
#include <SDL.h>
#include "Functions.h"
using namespace std;
class Sprite1
{
private:
int PosX;
int PosY;
int xDist;
int yDist;
string ImagePath;
SDL_Surface Screen;
SDL_Surface *temp, *sprite, *screen;
public:
Sprite1(int PosX, int PosY, string ImagePath, SDL_Surface Screen );
void DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen);
void DrawJon();
void MoveJon(int xDist, int yDist);
};
EDIT:
upon further investigation, it is this line
DrawSprite1Jon(PosX, PosY, sprite, screen);
That is failing in the DrawJon()
At least this piece of your code is broken:
string ImagePath;
char * writable = new char[ImagePath.size() + 1];
copy(ImagePath.begin(), ImagePath.end(), writable);
writable[ImagePath.size()] = '\0';
You are creating local ImagePath variable, not using the class member variable. The local variable shadows the member variable. Remove the local variable (first line in above snippet).
Also, you can probably (I'm not very familiar with SDL) do the loading simply like this:
temp = SDL_LoadBMP(ImagePath.c_str());
Then, just guessing, but image loading might be failing, and that function returns NULL pointer. So check return value and then check the error (either there is some SDL error function you can call, or you need to check standard errno global variable.
Further suggestion: turn on compiler warnings (for gcc: -W -Wall) and learn to understand (copying the warning to google is a good start) and then fix the warnings. Most of the time they are real bugs (hence the warning!) and even when they are not, fixing the warning will make your code better.
I is apparent that you've just began to program in C++, maybe you have a javascript background, therefore you've tried to put function declarations into the constructor. It is a wrong idea here. (#pragma's usually have some explicit meaning, you also misuse them here. see eg. #pragma GCC poison)
I see a lot of confusion in this code.
I suggest, you grab a great quality beginner C++ book, before going ahead with this piece of code. At this point I see no reason trying to hammer-out something reasonable from this code.
There were some problems with my implementation but in the end I had to build in release mode rather than debug mode.
Related
I'm quite confused about the reasoning behind the behaviour of pointers to a variable. I would have thought that if I append a pointer to a vector and access it, whether I changed the pointer itself it should still work the same upon the same variable. What I mean by this is, for example, I have a vector of integer pointers and I modify a variable defined somewhere else that has been appended to the vector. If I was to then print them, it should update the vector (not in reality) but it should print the new value of an integer. I'm trying to apply this to an SDL_Texture* in SDL2, however it doesn't quite make sense. In summary, the same concept is applying there however I am using Textures instead. I modify the texture and do "things" with it, but at the end of the loop when I render it, the vector is still iterating to the SDL_Texture* appended to it anyway. What my problem is, is as I change and modify the texture, when I go to render it it doesn't show up. This isn't because the texture isn't properly loaded or anything (I have tested it and rather than using the vector, I draw it raw) but when using the vector it doesn't work properly. Here is the code:
void Main::Mainloop()
{
Screen_Object m_Screen_Object;
TTF_Font* font = TTF_OpenFont("Anonymous_Pro.ttf", 30);
SDL_Surface* surf = TTF_RenderText_Blended(font, "Starting fps", {0,0,0});
SDL_Texture* tex = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf);
SDL_FreeSurface(surf);
SDL_Rect rct = {20, 100, 0,0};
SDL_QueryTexture(tex, NULL, NULL, &rct.w, &rct.h);
m_Screen_Object.Add_Texture(tex);
Uint32 start, finish, counter;
counter = 0;
start = SDL_GetTicks();
finish = SDL_GetTicks();
bool running = true;
while (running)
{
Events::Event_Loop();
if (Events::Quit_Application()){
running = false;
break;
}
///Clear display to color
SDL_SetRenderDrawColor(Render::Get_Renderer(), 0,255,0,255);
SDL_RenderClear(Render::Get_Renderer());
///Do stuff here
m_Screen_Object.Draw_Textures();
finish = SDL_GetTicks();
counter += 2;
if (finish - start >= 500)
{
start = SDL_GetTicks();
SDL_DestroyTexture(tex);
std::string fps = std::to_string(counter);
surf = TTF_RenderText_Blended(font, fps.c_str(), {0,0,0});
tex = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf);
SDL_FreeSurface(surf);
SDL_QueryTexture(tex, NULL, NULL, &rct.w, &rct.h);
counter = 0;
}
SDL_RenderPresent(Render::Get_Renderer());
}
SDL_DestroyTexture(tex);
TTF_CloseFont(font);
}
int main(int argc, char* argv[])
{
Main::Mainloop();
return 0;
}
and here is the declaration of Screen_Object:
In the header:
std::vector < SDL_Texture* > m_Textures;
In the .cpp:
void Screen_Object::Add_Texture(SDL_Texture* p_Texture)
{
m_Textures.push_back(p_Texture);
}
void Screen_Object::Draw_Textures()
{
for (unsigned int i=0; i < m_Textures.size(); i++)
{
SDL_RenderCopy(Render::Get_Renderer(), m_Textures[i], NULL, &m_Rect);
}
}
Now this code doesn't work in the way I believe it should since I can't understand why it isn't working, but when I change the vector's type to be SDL_Texture**, the code works fine. What on earth is wrong with the code without the **, I just can't logically understand why it won't work properly
The issue seems to be that you are storing pointers in the vector, but outside the vector you are invalidating the pointer.
void Screen_Object::Add_Texture(SDL_Texture* p_Texture)
{
m_Textures.push_back(p_Texture);
}
void Main::Mainloop()
{
Screen_Object m_Screen_Object;
//...
SDL_Texture* tex = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf);
//...
m_Screen_Object.Add_Texture(tex); // <-- add pointer to vector
//...
tex = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf); // <-- This changes the pointer, but has no effect on the vector's
//...
So anything after that line, if you access the pointer in m_Textures vector, that pointer in the vector is no longer valid, or worse, it is valid, but points to an old (but still valid) SDL_Texture.
A very simple solution is to ensure that you use the pointer you stored in the m_Textures by obtaining a reference to that pointer:
void Main::Mainloop()
{
Screen_Object m_Screen_Object;
TTF_Font* font = TTF_OpenFont("Anonymous_Pro.ttf", 30);
SDL_Surface* surf = TTF_RenderText_Blended(font, "Starting fps", {0,0,0});
SDL_Texture* tex = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf);
m_Screen_Object.Add_Texture(tex); // <-- Immediately do this
auto& texRef = m_Screen_Object.back(); // <-- Get a reference to the pointer.
Then you use texRef after that. This is the actual reference to the pointer you added to the vector, and not a copy of the pointer.
Then the loop would be simply:
texRef = SDL_CreateTextureFromSurface(Render::Get_Renderer(), surf);
This changes the actual pointer stored in the vector.
I am trying to load a bitmap animation to the screen. I have a float variable holdTime that is specified to hold the "holdtime" value for the animation. In my constructor I set the holdtimevariable to 0.1f but when I try to access the method in the class that is using the holdTime variable, the value of holdTime has changed to -107374176f. So somewhere between my constructor call and the method call the value has changed from 0.1f to -107374176f.
To make things a little bit more clearer let me show you some code:
Here is the header file for the Game class, this is where I call the constructor of the Animation class that has the holdTime variable.
#pragma once
#include "Graphics.h"
#include "Surface.h"
#include "Animation.h"
#include "FrameTimer.h"
class Game
{
public:
Game( class MainWindow& wnd );
void Go();
private:
void UpdateModel();
private:
MainWindow& wnd;
FrameTimer ft;
Surface surf = Surface("Test32x48.bmp");
Animation testAnimation = Animation(0, 0, 32, 48, 4, surf, 0.1f);
};
You see that I have this testAnimation at the bottom of the class. The last argument in the constructor call is the value that is ought be in holdTime.
This is how my Animation header file looks like:
#include "Surface.h"
#include "Graphics.h"
#include <vector>
class Animation {
public:
Animation(int x, int y, int width, int height, int count, const Surface& sprite, float holdtime, Color chroma = Colors::Magenta);
void Update(float dt);
private:
void Advance();
private:
std::vector<RectI> frames;
int iCurFrame = 0;
float holdTime = 0;
float curFrameTime = 0.0f;
};
And this is the Animation Cpp file:
#include "Animation.h"
Animation::Animation(int x, int y, int width, int height, int count,
const Surface& sprite, float holdtime, Color chroma)
:
sprite(sprite),
holdTime(holdTime),
chroma(chroma)
{
for (int i = 0; i < count; i++)
{
frames.emplace_back(x + i * width, x + (i + 1) * width,y, y + height);
}
}
void Animation::Update(float dt)
{
curFrameTime += dt;
while(curFrameTime >= holdTime) {
Advance();
curFrameTime -= holdTime;
}
}
void Animation::Advance()
{
if (++iCurFrame >= frames.size()) {
iCurFrame = 0;
}
}
There is only one method that is making use of holdTime and that is the method Update(float dt).
If we go back to the Game class and look at the Game.cpp file:
#include "MainWindow.h"
#include "Game.h"
Game::Game( MainWindow& wnd )
:
wnd( wnd ),
gfx( wnd )
{
}
void Game::Go()
{
UpdateModel();
}
void Game::UpdateModel()
{
testAnimation.Update(ft.Mark());
}
In the Method Go() we call the method UpdateModel() which in turn is calling the Update() method in the animation class. This means that the first method to be executed in the Animation class after the constructor call is the update() method. When I debug the program I can see that the value of holdtime has changed between the constructor call and the Update() method call. But I don't know how since it I am not modifying the value somewhere else. It also seemes that the new value of holdTime is garbage value.
It became a lot of code in this question and it looks a bit messy and even though I lack the skills of writing a good Title I hope I made you somewhat clear what my problem is.
Thanks!
Update:
Here is the code for the FrameTimer class since the value returned from one of its methods is passed in into the Update() method:
FrameTimer.H:
#pragma once
#include <chrono>
class FrameTimer
{
public:
FrameTimer();
float Mark();
private:
std::chrono::steady_clock::time_point last;
};
FrameTimer.cpp:
#include "FrameTimer.h"
using namespace std::chrono;
FrameTimer::FrameTimer()
{
last = steady_clock::now();
}
float FrameTimer::Mark()
{
const auto old = last;
last = steady_clock::now();
const duration<float> frameTime = last - old;
return frameTime.count();
}
Edit:
main.cpp:
int WINAPI wWinMain( HINSTANCE hInst,HINSTANCE,LPWSTR pArgs,INT )
{
MainWindow wnd( hInst,pArgs );
Game game( wnd );
while( wnd.ProcessMessage() )
{
game.Go();
}
}
As you can see the game.Go() method is the first method that is called in main.
Your Animation constructor is at fault:
Animation::Animation(int x, int y, int width, int height, int count,
const Surface& sprite, float holdtime, Color chroma)
:
sprite(sprite),
holdTime(holdTime),
chroma(chroma)
{
for (int i = 0; i < count; i++)
{
frames.emplace_back(x + i * width, x + (i + 1) * width,y, y + height);
}
}
Here you attempt to initialise the member holdTime from the parameter holdTime.
Except, there is no parameter holdTime. There is only the parameter holdtime.
Hence instead you are actually initialising the member holdTime from itself (the next nearest "match" for that name), so it only retains its original, unspecified value (and in fact, reading an uninitialised variable results in your program having undefined behaviour).
So, you see, your member variable doesn't "change" at all — you never set it correctly. You'd have known that had you put some diagnostic output inside that constructor to examine the value and see whether it's what you thought it should be. None of the rest of the code was relevant or necessary.
A properly-configured compiler should have warned you about this.
I've been trying to wrap my head around the basics of SDL, and I'm stumped by what should seem simple.
SDL_MapRGB() requires const SDL_PixelFormat*, and I use a SDL_PixelFormatEnum for creating textures in my project which is unit32. But I can't find any way of converting it for use with SDL_MapRGB().
There's probably an easier way than using SDL_MapRGB(), but this problem would still confuse me, as you can easily convert it the other way.
Irrelevant, but if you wish to know the rest of the code, then their you go.
#include <SDL.h>
SDL_Window *sdlWindow;
SDL_Renderer *sdlRenderer;
int main( int argc, char *args[] )
{
int w = 640;
int h = 480;
Uint32 format = SDL_PIXELFORMAT_RGB888;
SDL_CreateWindowAndRenderer(w, h, 0, &sdlWindow, &sdlRenderer);
SDL_Texture *sdlTexture = SDL_CreateTexture(sdlRenderer, format, SDL_TEXTUREACCESS_STREAMING, w, h);
extern uint32_t *pixels;
for (int x = 0; x < w; x++) {
for (int y = 0; y < h; y++) {
pixels[x + y * w] = SDL_MapRGB(format, 255, 255, 255);
}
}
SDL_UpdateTexture(sdlTexture, NULL, pixels, 640 * sizeof (Uint32));
SDL_RenderClear(sdlRenderer);
SDL_RenderCopy(sdlRenderer, sdlTexture, NULL, NULL);
SDL_RenderPresent(sdlRenderer);
SDL_Delay(5000);
SDL_Quit();
return 0;
}
Before you say it, I know this just makes a white screen.
So, SDL_PixelFormat and SDL_PixelFormatEnum are simply completely different types, you don't cast between them. You can ask SDL to lookup the SDL_PixelFormat corresponding to the Uint32 you mentioned though:
/**
* Create an SDL_PixelFormat structure corresponding to a pixel format.
*
* Returned structure may come from a shared global cache (i.e. not newly
* allocated), and hence should not be modified, especially the palette. Weird
* errors such as `Blit combination not supported` may occur.
*
* \param pixel_format one of the SDL_PixelFormatEnum values
* \returns the new SDL_PixelFormat structure or NULL on failure; call
* SDL_GetError() for more information.
*
* \since This function is available since SDL 2.0.0.
*
* \sa SDL_FreeFormat
*/
extern DECLSPEC SDL_PixelFormat * SDLCALL SDL_AllocFormat(Uint32 pixel_format);
Source: SDL2 header
SDL docs are often a bit spotty, but my goto info places when I'm not sure about some SDL thing are for example, these pages first, then just go look in the SDL2 headers themselves, then maybe Google it and hope it's mentioned in a forum post or something.
Hope this helped. (Note that I didn't try to compile anything here)
new here, so be gentle, I'm currently doing my Major Project for my course and, I'm not asking for homework to be done for me, i just can't wrap my head around a strange problem i am having and have not been able to find an answer for it, even on here. I'm using SDL for my Drawing.
I'm doing Object Orientated Programming with my Project or a "state Machine" (which sounds less painful in a newbies mind, believe me), and in the render part of my Class Game1.cpp i am trying to call a Draw Function of my Player Class, but for some unknown reason that i can not fathom, it just skips this function call completely.
I have no errors, i even used breakpoints to find out what was happening, but it just skipped it completely every time, it is drawing the screen black as well without fail. Any help as t why it is skipping this would be really appreciated.
I honestly feel like it's a simple rookie mistake, but any and all scrutiny is welcome of my code, anything i can do to better myself is appreciated.
Game1.cpp:
#include "Game1.h"
#include "PlayerCharacter.h"
Game1::Game1( World * worldObject )
{
//object setup
this->worldObject = worldObject;
setDone (false);
}
Game1::~Game1()
{
}
void Game1::handle_events()
{
//*******************************************
//**//////////////Call Input///////////////**
//*******************************************
//******Check for Keyboard Input*************
//******Check Keyboard Logic*****************
//******Check for Mouse Input****************
//The mouse offsets
x = 0, y = 0;
//If the mouse moved
if (SDL_PollEvent(&worldObject->event))
{
if( worldObject->event.type == SDL_MOUSEMOTION )
{
//Get the mouse offsets
x = worldObject->event.motion.x;
y = worldObject->event.motion.y;
}
}
//******Check Mouse Logic********************
}
void Game1::logic()
{
//*******************************************
//**//////////Collision Detection//////////**
//*******************************************
//******Check Player Bullet Collision Loop***
//Check for collision with enemies
//Check for collision with bitmap mask (walls)
//******Check Enemy Bullet Collision Loop****
//Check for Collision with Player
//Check for collision with bitmap mask (walls)
}
void Game1::render()
{
//*******************************************
//**////////////////Drawing////////////////**
//*******************************************
//******Blit Black Background****************
SDL_FillRect(worldObject->Screen , NULL , 0xff000000);
//******Blit Bitmap Mask*********************
//******Blit Flashlight**********************
//******Blit Map*****************************
//******Blit Pickups*************************
//******Blit Bullets*************************
//******Blit Player**************************
&PlayerCharacter.Draw; // <----- Skips this line completely, no idea why
//******Blit Enemies*************************
//******Blit Blackened Overlay***************
//******Blit HUD*****************************
//******Flip Screen**************************
SDL_Flip(worldObject->Screen);
}
Game1.h
#ifndef __Game1_H_INLUDED__
#define __Game1_H_INLUDED__
#include "GameState.h"
#include "SDL.h"
#include "ImageLoader.h"
using namespace IMGLoader;
class Game1 : public GameState
{
private:
//Menu Image
World * worldObject;
SDL_Rect PauseMenu,Item1Tile,Item2Tile,Item3Tile;
/*bool bPauseMenu, bItem1Tile, bItem2Tile, bItem3Tile;
int ButtonSpace,ButtonSize;
float x,y;
int Alpha1,Alpha2;*/
//Clipping Window
//SDL_Rect sclip,dclip;
public:
//Loads Menu resources
Game1 (World * worldObject);
//Frees Menu resources
~Game1();
//Main loop functions
void handle_events();
void logic();
void render();
};
#endif
PlayerCharacter.cpp
#include "PlayerCharacter.h"
SDL_Rect psclip,pdclip;
PlayerCharacter::PlayerCharacter ( float X, float Y, float dX, float dY, float Angle, float Speed, bool Existance, int Height, int Width, int Health, int Shield, SDL_Surface* Player ):Characters ( X, Y, dX, dY, Angle, Speed, Existance, Height, Width, Health )
{
this->Player = Player;
this->Shield = Shield;
this->Player = load_image("image\Player1.png");
}
void PlayerCharacter::setShield ( int Shield )
{
this->Shield = Shield;
}
int PlayerCharacter::getShield ( void )
{
return Shield;
}
void PlayerCharacter::Draw( )
{
psclip.x = 0; psclip.y = 0; psclip.w = 64; psclip.h = 64;
pdclip.x = 640; pdclip.y = 318; pdclip.w = 64; pdclip.h = 64;
SDL_BlitSurface(Player, &psclip, worldObject->Screen, &pdclip);
}
PlayerCharacter.h
#ifndef __PlayerCharacter_H_INCLUDED__
#define __PlayerCharacter_H_INCLUDED__
#include "Characters.h"
class PlayerCharacter : public Characters
{
private:
int Shield;
SDL_Surface* Player;
World *worldObject;
public:
PlayerCharacter ( float X, float Y, float dX, float dY, float Angle, float Speed, bool Existance, int Height, int Width, int Health, int Shield, SDL_Surface* Player );
void setShield ( int Shield );
int getShield ( void );
void Draw ( );
};
#endif
The line
&PlayerCharacter.Draw; // <----- Skips this line completely, no idea why
is not actually a function call. It's an expression that take the address of the Draw function in the PlayerCharacter class and does nothing with it.
I'm actually kind of surprised it compiles without errors, or at least tons of warnings.
You need to create a PlayerCharacter object, and then call the function in the object.
&PlayerCharacter.Draw is not a function call. PlayerCharacter::Draw() is not a static class method, so you need a PlayerCharacter object to invoke this method on.
You have a class PlayerCharacter, which defines what a PlayerCharacter is and what can be done with it. But as far as I see, you don't have a single PlayerCharacter object, i.e. no player character. If you had one, let's call him pc, then you could draw him with pc.Draw(). For that, you would have to instantiate the class, e.g. via PlayerCharacter pc( ... ), with the ... replaced by some appropriate values for the multitude of constructor parameters you have there. (You really want a default constructor, initializing all those to zero or other appropriate "start" value...)
This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
How do you get a minimal SDL program to compile and link in visual studio 2008 express?
So I am new to C++ and need to create a class. I think this has something to do with the implementation of the methods in the Sprite.cpp.
Can someone give me an example of a simple class with properties and a method. Or at least let me know what I am doing wrong?
Error #1
Error 12 error LNK2019: unresolved external symbol __imp___CrtDbgReportW referenced in function "public: void __thiscall std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> >::_Compat(class std::_String_const_iterator<char,struct std::char_traits<char>,class std::allocator<char> > const &)const " (?_Compat#?$_String_const_iterator#DU?$char_traits#D#std##V?$allocator#D#2##std##QBEXABV12##Z) D:\GSE\Game with Jon Bye\game\game\main.obj
Error #2
Error 13 error LNK1120: 1 unresolved externals D:\GSE\Game with Jon Bye\game\Debug\game.exe 1
Sprite.h
#include <string>
#include <SDL.h>
#include "Functions.h"
using namespace std;
class Sprite
{
private:
int PosX;
int PosY;
int xDist;
int yDist;
string ImagePath;
SDL_Surface Screen;
SDL_Surface *temp, *sprite, *screen;
public:
Sprite(int PosX, int PosY, string ImagePath, SDL_Surface Screen );
void Sprite::DrawSprite( int x, int y, SDL_Surface *sprite, SDL_Surface *screen )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;
//Give the offsets to the rectangle
offset.x = x;
offset.y = y;
//Blit the surface
SDL_BlitSurface( sprite, NULL, screen, &offset );
SDL_UpdateRect(screen, 0, 0, 0, 0);
}
void Sprite::Draw()
{
#pragma region Char to String Conversion
string ImagePath;
char * writable = new char[ImagePath.size() + 1];
copy(ImagePath.begin(), ImagePath.end(), writable);
writable[ImagePath.size()] = '\0';
#pragma endregion
temp = SDL_LoadBMP(writable);
sprite = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);
// free the string after using it
delete[] writable;
DrawSprite(PosX, PosY, sprite, screen);
}
void Sprite::Move(int xDist, int yDist)
{
PosX += xDist;
PosY += yDist;
Draw();
};
};
Sprite.cpp
#include "Sprite.h"
Sprite::Sprite(int posX, int posY, std::string imagePath, SDL_Surface screen) : PosX(posX), PosY(posY), ImagePath(imagePath), Screen(screen)
{
void DrawSprite( int x, int y, SDL_Surface *sprite, SDL_Surface *screen );
void Draw();
void Move(int xDist, int yDist);
}
Ah my buddy Jonathan O! Looks like you took my advice to use SDL after all...
I'm not sure what your error means, but I know that in SDL, you need to put this:
#undef main
After your:
#include <SDL.h>
Or else it will not work. Why? For some reason SDL defines "main" somewhere, so the linker freaks out when you include "SDL.h", and gets all confused (since main is the entry function).
Perhaps this is the source of your error, although I doubt it, the error message looks like it has something to do with strings...
Also, I don't really get what's going on in your Sprite.CPP file. If you're still new to C++ and looking at how to create classes in C++, you'll find some C++ tutorials here, it's how I started learning C++: http://thenewboston.org/list.php?cat=16
Unresolved externals in C++ when using vectors and find
I was in debug mode and not release mode.
Make sure you set up the linker settings etc in the new Release mode that you have selected and that you are building the Release project.