UnitManager m_unitManager;
Game.h:53: error: field `m_unitManager' has incomplete type.
I think that means it sees that UnitManager is a class, but not the
implementation. If I try without the 'forward include' (I think it's called?
Using 'class UnitManager;' in Game.h ) I get: Game.h:48: error: using-declaration for non-member at class scope
I didn't include the .cpp files because I thought it wasn't neccessary. Do you
need to know or see anything else?
Game.h
[source lang="cpp]//Game.h
#ifndef RTS_GAME_H
#define RTS_GAME_H
// About: Class that controls everything
//standard
//#include <iostream>
#include "globals.h"
#include "Actor.h"
#include "UnitManager.h"
namespace rts {
class UnitManager; //forward include, unsure if I need this.
class Game
{
public:
Game();
~Game();
/*! init data */
void init(void);
/*! act on the events */
void event( SDL_Event const & event );
/*! draw the game */
void render(void);
/*! update the game */
void update(void);
private:
//several tests, see below for errors:
//test: UnitManager m_unitManager; //!< manager of a list of Unit() derived classes
//UnitManager m_unitManager;
//rts::UnitManager m_unitManager; //!< manager of a list of Unit() derived classes
/* the error for 'rts::UnitManager m_unitManager;' is:
Game.h:48: error: field `m_unitManager' has incomplete type
*/
//rts::UnitManager m_unitManager; //!< manager of a list of Unit() derived classes
/* the error for 'UnitManager m_unitManager;' is:
Game.h:53: error: field `m_unitManager' has incomplete type
*/
//UnitManager m_unitManager; //!< manager of a list of Unit() derived classes
/* the error for 'rts::Unit m_test;' is:
Game.h:58: error: field `m_test' has incomplete type
*/
//rts::Unit m_test;
/* the error for 'Unit m_test;' is:
Game.h:63: error: field `m_test' has incomplete type
*/
//Unit m_test;
};
} //namespace rts
#endif //RTS_GAME_H
//UnitManager.h
#ifndef RTS_UNIT_MANAGER_H
#define RTS_UNIT_MANAGER_H
// About: class that manages a lists of Unit()'s
#include "globals.h" //!< for log
#include <boost/ptr_container/ptr_vector.hpp> //!< for boost::ptr_vector
#include "Actor.h" //!< for Unit() , But it might move to Unit.h
namespace rts {
class Unit; //!< forward declaration for UnitManager() to see Unit()
/*! a class that manages a list of Unit() derived classes */
class UnitManager
{
public:
public:
/*! typedef for convienence and/or sanity / code clarity */
typedef boost::ptr_vector<Unit> UnitPtr;
UnitManager();
~UnitManager();
//! add a Unit() derived class to a boost list
void addUnit( Unit *u );
//! update all Unit()'s in the list
void update( float elapsed );
//! render all Units()'s in the list
void render( void );
protected:
private:
/*! list of Unit() derived classes using boost::ptr_vector<Unit> */
UnitPtr m_unitList;
};
} //namespace rts
#endif //RTS_UNIT_MANAGER_H
//actor.h
#ifndef RTS_ACTOR_H
#define RTS_ACTOR_H
// About: Contains base class for unit/building polymorphism
#include <boost/utility.hpp> //!< for boost::noncopyable
#include "source/jakelib/Vector3d.h" //!< a math/location vector
#include "globals.h" //<! for jakelib::Graphics2d
namespace rts {
/*! base actor class. Unsure if I want it to be noncopyable */
class Actor : boost::noncopyable
{
public:
Actor() : m_location(0,0,0) {}
Actor(Vector3d loc) : m_location(loc) {}
virtual ~Actor(){}
//! update location, keep within screen bounds
virtual void update(float fps);//was: virtual void update(float elapsed) = 0;
//! (was pure virtual), derived class overrides to render the unit
virtual void render(void) {} //was: virtual void render(void) const = 0;
private:
protected:
Vector3d m_location; //<! coordinates in 2d/3d space
};
/*! Building() derives from Actor(), base class for buildings */
class Building : public Actor
{
public:
Building(){}
virtual ~Building(){}
/*! update specific to all buildings */
virtual void update(float elapsed);
/*! render specific to all buildings */
virtual void render();
protected:
private:
};
/*! Unit() derives from Actor(), base class for units */
class Unit : public Actor
{
public:
Unit(){}
Unit(Vector3d loc) : Actor(loc){}
virtual ~Unit(){}
/*! basic update for all units */
virtual void update(float elapsed);
/*! basic render for all units */
virtual void render(void);
protected:
private:
};
} //namespace rts
#endif //RTS_ACTOR_H