Napisano: 05 Apr 2010 1:57
Pozdrav,opet ja sa pocetnickim pitanjem,ali ne znam sta da trazim.
imam mapu <string,GameObject*>
e,sad,kad u nju ubacujem GameObject-e sve je ok,problem nastaje kad pokusam da ubacim klasu Ship (koja je izvedena od klase GameObject) u tu mapu. Code::Blocks mi prijavljuje gresku : "GameObject is inaccessible base of Ship". Na koji nacin ovo da sredim ima li neko ideju ?
Dopuna: 09 Apr 2010 19:17
Posto vidim da niko ne odgovara,mozda ce pomoci da bolje objasnim moj problem
Copy/paste je sa stranog foruma,nadam se da nije problem sto je na engleskom
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:
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
#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
#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
#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
#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
Dopuna: 10 Apr 2010 2:10
Resio,trebalo je
class Ship : public GObject
|