Wow this was fast :D. Sorry I took so long, but I had to clean that messy code of mine up.
@Peter87:
The code up there just serves as an example. The file in my Project is called "CPlayer.h" ;)
@Little Bobby Tables
Thanks!
@Stewbond
Aaargh! You found a mistake... This is also en error who happens to be there because I wrote the code example and didn't copy it out of my project. I did not learn much about inheritance (it is inheritance in your example isnt it?). I do not have something like a Default constructor... And I don't have a constructor with the same name (if thats what you mean by confuse)...
There are some SDL-funtions within the code, but I guess you can just ignore them, since they don't have much to do with the errors.
Actual Code:
So here are the four files I actually use in my project (they aren't even close to being finished yet).
CSprite.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27
|
#ifndef _CSPRITE_H_
#define _CSPRITE_H_
#include "SDL.h"
#include "SDL_image.h"
#include "CGame.h"
class CSprite
{
public:
CSprite();
public:
void Load(const char* cPath, int R, int G, int B);
void Render ();
private:
SDL_Rect rcDest;
SDL_Surface* sImage;
SDL_Texture* tImage;
CGame Game; //<-- Creates error message no 1)
};
#endif // _CSPRITE_H_
|
1) Error: 'CGame' does not name a type
CSprite.cpp
#include "CSprite.h"
#include <iostream>
CSprite::CSprite()
{
sImage = NULL;
tImage = NULL;
}
void CSprite::Load (const char* cPath, int R, int G, int B)
{
sImage = IMG_Load(cPath);
if (sImage == NULL)
{
std::cout << "Fehler beim Laden von " << cPath << "! SDL_Error: " << SDL_GetError() << "\n";
}
else
{
SDL_SetColorKey(sImage, SDL_TRUE, SDL_MapRGB(sImage-> format, R, G, B));
tImage = SDL_CreateTextureFromSurface(Game.GetRenderer(), sImage); //<-- Creates error message no 2)
if (tImage == NULL)
{
std::cout << "Fehler beim Umwandeln von einer Surface in eine Textur der Grafik " << cPath << "! SDL_Error: " << SDL_GetError() <<"\n";
}
SDL_FreeSurface (sImage);
}
}
void CSprite::Render()
{
SDL_RenderCopy (Game.GetRenderer(),tImage,NULL,&rcDest); //<-- Creates error message no 3)
}
[/code]
2) Error: Game was not declared in this scope
3) Error: Game was not declared in this scope
CPlayer.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
|
#ifndef _CPLAYER_H_
#define _CPLAYER_H_
#include "CSprite.h"
#include "CGame.h"
#include <string>
class CPlayer
{
public:
CPlayer();
public:
void Init();
void Render();
private:
CSprite SpritePlayer; //<-- Creates error message no 4)
};
#endif // _CPLAYER_H_
|
4) Error: 'CSprite' does not name a type
CPlayer.cpp
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
|
#include "CPlayer.h"
#include "CGame.h"
CPlayer::CPlayer()
{
}
void CPlayer::Init()
{
SpritePlayer.Load("data/imgs/player/Ash_Player.bmp", 255, 0, 255); //<-- Creates error message no 5)
}
void CPlayer::Render()
{
SpritePlayer.Render(); //<-- Creates error message no 6)
}
|
5) Error: SpritePlayer was not declared in this scope
6) Error: SpritePlayer was not declared in this scope
(Somehow the "Preview"-Button is not working. Hope it doesn't look too bad in the real post)
Thank you for all the fast answers so far!
Cheers Half_NO_oB