Jeg har lavet følgende kode:
spriteLib.h
- #ifndef SPRITELIB_H_
- #define SPRITELIB_H_
-
- #include "SDL/SDL.h"
- #include "SDL/SDL_image.h"
- #include <string>
- #include <map>
-
- class SpriteLib {
- private:
- map<string, SDL_Surface*> images;
- SDL_Surface* loadImage(string filePath);
- public:
- SpriteLib();
- virtual ~SpriteLib();
-
- SDL_Surface* getImage(string filePath);
- };
-
- #endif
spriteLib.cpp
- #include "SpriteLib.h"
-
- SpriteLib::SpriteLib() {}
- SpriteLib::~SpriteLib() {}
-
- SDL_Surface* SpriteLib::loadImage(string filePath) {
- SDL_Surface* loadedImage = NULL;
- SDL_Surface* optimizedImage = NULL;
-
- loadedImage = SDL_LoadBMP( filename.c_str() );
-
- if( loadedImage != NULL )
- {
- optimizedImage = SDL_DisplayFormat( loadedImage );
-
- SDL_FreeSurface( loadedImage );
- }
- return optimizedImage;
- }
-
- SDL_Surface* getImage(string filePath) {
- if(images[filePath] == NULL) {
- images[filePath] = loadImage(filePath);
- }
- return images[filePath];
- }
Jeg får følgende fejl:
**** Build of configuration Debug for project SDLappOne ****
**** Internal Builder is used for build ****
g++ -O0 -g3 -Wall -c -fmessage-length=0 -osrc\SpriteLib.o ..\src\SpriteLib.cpp
In file included from ..\src\SpriteLib.cpp:8:
..\src\SpriteLib.h:18: error: ISO C++ forbids declaration of `map' with no type
..\src\SpriteLib.h:18: error: expected `;' before '<' token
..\src\SpriteLib.h:19: error: expected `;' before '(' token
..\src\SpriteLib.h:24: error: expected `;' before '(' token
..\src\SpriteLib.cpp:19: error: `SDL_Surface*SpriteLib::loadImage' is not a static member of `class SpriteLib'
..\src\SpriteLib.cpp:19: error: `string' was not declared in this scope
..\src\SpriteLib.cpp:19: error: expected `,' or `;' before '{' token
..\src\SpriteLib.cpp:34: error: `string' was not declared in this scope
..\src\SpriteLib.cpp:34: error: expected `,' or `;' before '{' token
Build error occurred, build is stopped
Time consumed: 270 ms.
Det er som om den ikke forstår hvad der er variabler, og hvad der er funktionenr.
Indlæg senest redigeret d. 01.01.2009 17:17 af Bruger #13669