compiler output:
g++ -Wall -g main.cpp `sdl-config --cflags --libs` -lSDL_mixer
In file included from Game.h:8,
from main.cpp:1:
DrawableObject.h:11: error: ISO C++ forbids declaration of ‘Game’ with no type
DrawableObject.h:11: error: expected ‘;’ before ‘*’ token
DrawableObject.h:13: error: expected ‘)’ before ‘*’ token
main.cpp:7: error: expected ‘}’ at end of input
main.cpp:7: error: expected unqualified-id at end of input
make: *** [all] Error 1
brett@brett-laptop:~/Desktop/SDL$ make
g++ -Wall -g main.cpp `sdl-config --cflags --libs` -lSDL_mixer
In file included from Game.h:8,
from main.cpp:1:
DrawableObject.h:11: error: ISO C++ forbids declaration of ‘Game’ with no type
DrawableObject.h:11: error: expected ‘;’ before ‘*’ token
DrawableObject.h:13: error: expected ‘)’ before ‘*’ token
main.cpp:7: error: expected ‘}’ at end of input
main.cpp:7: error: expected unqualified-id at end of input
make: *** [all] Error 1
main.cpp:
#include "Game.h"
int main()
{
Game g;
return 0;
}
Game.h:
#ifndef GAME_H
#define GAME_H
#include <cmath>
#include "SDL.h"
#include <vector>
#include "DrawableObject.h"
typedef unsigned char uint8;
typedef unsigned short uint16;
typedef unsigned int uint32;
class Game
{
public:
SDL_Surface * screen;
std::vector<DrawableObject*> sprites;
Game()
{
if (SDL_Init(SDL_INIT_VIDEO) != 0)
return;
atexit(SDL_Quit);
screen = SDL_SetVideoMode(640, 480, 0, SDL_DOUBLEBUF);
if (screen == NULL)
return;
while (true)
{
SDL_Event * event;
while(SDL_PollEvent(event))
{
if(event->type == SDL_QUIT)
return;
}
SDL_LockSurface(screen);
for (uint32 i=0; i<sprites.size(); ++i)
{
sprites[i]->update(event);
}
SDL_FreeSurface(screen);
SDL_Flip(screen);
}
};
#endif
DrawableObject.h:
#ifndef DRAWABLE_OBJECT_H
#define DRAWABLE_OBJECT_H
#include "SDL.h"
#include "Game.h"
class DrawableObject
{
public:
Game * game;
DrawableObject(Game * const game_)
: game(game_)
{}
virtual void update(SDL_Event *event) = 0;
};
#endif