First,hello everyone :)
I started making a game in C++ and i'm stuck at this point.
1. I have class GObject (thats game object class,with x,y coordinates,sprite info etc)
2. I have Ship and its base class is GObject (class Ship : GObject)
3. I have map<string,GObject*> which "contains" all game objects so i can draw,update and do stuff with them.
Now,here is the problem: when i put:
1 2
|
gameObjects["first"] = new Ship(15,20,"sprite_name");
|
I get this error (i'm using Code::Blocks on linux) : 'GObject' is inacessible base of 'Ship'.
Here are ship and gobject files. Maybe it will help :) :
Ship.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14
|
#ifndef SHIP_H_INCLUDED
#define SHIP_H_INCLUDED
#include "GObject.h"
#include <string>
#include <SDL.h>
class Ship : GObject
{
public:
Ship(int,int,std::string);
virtual void KeyDown(Uint8*);
};
#endif // SHIP_H_INCLUDED
|
Ship.cpp
1 2 3 4 5 6 7 8 9
|
#include <string>
#include "Ship.h"
Ship::Ship(int x,int y,std::string ime) : GObject(x,y,ime) { }
void Ship::KeyDown(Uint8* kstates)
{
if (kstates[SDLK_UP]) x += 10;
}
|
GObject.h
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
|
#ifndef GOBJECT_H_INCLUDED
#define GOBJECT_H_INCLUDED
#include <string>
#include <SDL.h>
#include <cstdlib>
class GObject
{
public:
GObject(int,int,std::string);
virtual void KeyDown(Uint8*);
int x, y;
std::string spritename;
};
#endif // GOBJECT_H_INCLUDED
|
GObject.cpp
1 2 3 4 5 6 7 8 9 10
|
#include "GObject.h"
#include <string>
#include <SDL.h>
GObject::GObject(int cx,int cy,std::string cspritename) : x(cx), y(cy), spritename(cspritename) {}
void GObject::KeyDown(Uint8*)
{
}
|
Thanks in advance for help :)