Izvedene klase u containeru glavne klase

Izvedene klase u containeru glavne klase

offline
  • Pridružio: 10 Avg 2006
  • Poruke: 1009
  • Gde živiš: Beograd

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 ? Embarassed

Dopuna: 09 Apr 2010 19:17

Posto vidim da niko ne odgovara,mozda ce pomoci da bolje objasnim moj problem Razz
Copy/paste je sa stranog foruma,nadam se da nije problem sto je na engleskom Very Happy

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 Smile :

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 Smile

Dopuna: 10 Apr 2010 2:10

Resio,trebalo je

class Ship : public GObject

Razz



Registruj se da bi učestvovao u diskusiji. Registrovanim korisnicima se NE prikazuju reklame unutar poruka.
Ko je trenutno na forumu
 

Ukupno su 1060 korisnika na forumu :: 30 registrovanih, 3 sakrivenih i 1027 gosta   ::   [ Administrator ] [ Supermoderator ] [ Moderator ] :: Detaljnije

Najviše korisnika na forumu ikad bilo je 3466 - dana 01 Jun 2021 17:07

Korisnici koji su trenutno na forumu:
Korisnici trenutno na forumu: A.R.Chafee.Jr., asdfjklc, bojcistv, bokisha253, CrazySerb_MLD, croato, dijica, DPera, dragon986, Duh sa sekirom, francis begbie, Lucije Kvint, mercedesamg, Milos ZA, milos.cbr, MilosKop, milutin134, Miškić, nebkv, nenad81, novator, Parker, repac, Srky Boy, stegonosa, t84dar, W123, wolf431, YugoSlav, Žoržo