My compiler is bitching about not being able to allocate an instance of MyGame because some of its methods are pure virtual, I've given the methods definitions in the subclass but it doesn't seem to care.
#pragma once
#include <SDL/SDL.h>
#include <SDL/SDL_opengl.h>
//Abstract class
class Game {
private:
int requestedFPS;
int reportedFPS;
SDL_Surface* screen;
int width;
int height;
public:
Game(int width, int height);
virtual ~Game();
virtual void update() const = 0;
virtual void render() const = 0;
virtual void init() const = 0;
virtual void keyEvent(int event, int key) const = 0;
virtual void mouseEvent(int event, int x, int y, int button) const = 0;
int getRequestedFPS();
int getReportedFPS();
void setRequestedFPS(int requestedFPS);
void setReportedFPS(int reportedFPS);
int getWidth();
int getHeight();
};
#pragma once
#include "Game.h"
class MyGame : public Game {
public:
MyGame(int width, int height);
virtual void init();
virtual void update();
virtual void render();
virtual void keyEvent(int event, int key);
virtual void mouseEvent(int event, int x, int y, int button);
};
I'd need to see the FBengine class (more specifically the setGame method) and the exact error message before I can give you an answer. From the code given, it seems perfectly fine.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
You can only use pointers to an abstract class, with memory allocated to a derived class e.g.
Base* pBase = new Derived();
This is one method of polymorphism in C++.
just thought I would elaborate further on the previous (you cant't instantiate abstract classes)
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
#pragma once
#include "Game.h"
class MyGame : public Game {
public:
MyGame(int width, int height);
virtual void init() const;
virtual void update() const;
virtual void render() const;
virtual void keyEvent(int event, int key) const;
virtual void mouseEvent(int event, int x, int y, int button) const;
};
the error was caused because the implementations you defined were not const, so it thought you still had more things to define.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
ajtgarber wrote:I know this, but how do I get MyGame to not be an abstract class?
Simple answer without looking at the code, derive a new class and implement all of the methods that you haven't defined (the ones you declared as =0).
---------------------------------------------------------------------------------------
I think I can program pretty well, it's my compiler that needs convincing!
--------------------------------------------------------------------------------------- And now a joke to lighten to mood :D
I wander what programming language anakin skywalker used to program C3-PO's AI back on tatooine? my guess is Jawa :P
Thanks for all the help guys , now its giving me another error :P. I'm not really sure why though... sorry I'm not quite used to the C++ compiler messages yet
well maybe you should, instead of adding const's to your MyGame class, remove the const's from the Game abstract class. That would probably be the better strategy.
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.
Thanks :D, what exactly does the const after the function header actually mean? I remember reading somewhere that a function with const after it can't call another function that doesn't have it.
ajtgarber wrote:Thanks :D, what exactly does the const after the function header actually mean? I remember reading somewhere that a function with const after it can't call another function that doesn't have it.
A function with const after it cannot modify any data of the class. This is so that the compiler can tell if a method can be used safely by a const instance of the class, because if a function tries to modify const data, it won't work exactly the way you want it to.
ajtgarber wrote:P.S Ginto8 nice signature
Quit procrastinating and make something awesome.
Ducky wrote:Give a man some wood, he'll be warm for the night. Put him on fire and he'll be warm for the rest of his life.