Michael Sullivan wrote:
> OK.  New code and error messages:
> 
> [EMAIL PROTECTED] ourrpg $ nl battle.h
>      1  #ifndef __BATTLE_H__
>      2  #define __BATTLE_H__
>      3
>      4  #include <SDL/SDL.h>
>      5  #include "SDL/SDL_ttf.h"
>      6  #include <string>
>      7  #include "character.h"
>      8  #include "ally.h"
>      9
>     10  using namespace std;
>     11
>     12  class DrawBattle;
>     13  class Battle
>     14  {
>     15     public:
>     16        Battle();
>     17        ~Battle();
>     18        Ally* getParty() { return party; }
>     19        Ally* getParty(int i) { return &party[i]; }
>     20
>     21        bool initialize();
>     22        bool destroy();
>     23
>     24     private:
>     25        Ally party[4];
>     26        DrawBattle db;
>     27  };
>     28
>     29  class DrawBattle
>     30  {
<snip>
> [EMAIL PROTECTED] ourrpg $ make
> g++ `sdl-config --cflags` -I/usr/local/include/mysql++/
> -I/usr/include/mysql -L/usr/local/lib -c battle.cpp
> battle.h:26: error: field 'db' has incomplete type
> battle.cpp: In member function 'bool Battle::initialize()':
> battle.cpp:30: error: 'db' was not declared in this scope
> make: *** [battle.o] Error 1
> 
> Why does db have an incomplete type, and why was db "not declared in
> this scope"?

Because DrawBattle is a placeholder for the actual class and then you 
use the placeholder within another class as an instantiated object.  The 
compiler doesn't know the sizeof(DrawBattle) because it has only been 
declared as a placeholder.  Hence the error.  Needs to be a pointer or a 
smart pointer.  BUT...

Brett makes a valid point:  Battle shouldn't do any drawing if you have 
a class called DrawBattle...and therefore doesn't need to have a 
DrawBattle object in the first place.  Let DrawBattle manage drawing of 
the battle and Battle manage the battle logic.  DrawBattle communicates 
with Battle with access methods.  There really should also be a 
high-level interface that decides which drawing platform to use next - a 
layered state engine that also manages the _single_ necessary 
initialization and shutdown of SDL along with all SDL specific 
components necessary to run the game (e.g. textures, fonts, etc.).  The 
only game state you have now is a battle interface.  But you might have 
a main menu interface, a town interface, a party management interface, etc.

Personally, any time there is a pointer involved, I'd be using smart 
pointers and let the compiler manage everything.  Especially if player 
data is going to be used elsewhere other than in battles (e.g. walking 
around a city, moving potions from one player inventory to another, 
etc.).  But that's me.

It would really help us to know the depth of the game you are making so 
we don't blow this completely out of proportion.  I'm under the 
assumption you want to make a complete game with all the 
bells-and-whistles.  If all you ever want to do is have battles, you 
need to let us know this before we scope-creep the thing into an 
unnecessary beast.

-- 
Thomas Hruska
CubicleSoft President
Ph: 517-803-4197

*NEW* MyTaskFocus 1.1
Get on task.  Stay on task.

http://www.CubicleSoft.com/MyTaskFocus/

Reply via email to