   Vtm tutorial inheritance problem
Sprite.h#ifndef SPRITE_H#define SPRITE_H#include "DrawEngine.h"enum{SPRITE_CLASSID,CHARACTER_CLASSID,};struct vector{float x;float y;};class Sprite{public:Sprite(DrawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);~Sprite();vector getPosition(void);float getX(void);float getY(void);virtual void addLives(int num = 1);int getLives(void);bool isAlive(void);virtual bool move(float x, float y);protected:DrawEngine *drawArea;vector pos;int spriteIndex;int numLives;int classID;vector facingDirection;void draw(float x, float y);void erase(float x, float y);};#endifCharacter.h#ifndef CHARACTER_H#define CHARACTER_H#include "sprite.h"class Character : public Sprite{public:Character(DrawEngine *de, int s_index, float x = 1, float y = 1, int lives = 3, char up_key = 'w', down_key= 's', char left_key = 'a', char right_key = 'd');virtual bool keyPress(char c);protected:char upKey;char downKey;char leftKey;char rightKey;};#endiferror messagescharacter.cppcharacter.h(9) : error C2143: syntax error : missing ')' before '*'character.h(9) : error C2143: syntax error : missing ';' before '*'character.h(9) : error C2460: 'Character::DrawEngine' : uses 'Character', which is being definedcharacter.h(6) : see declaration of 'Character'character.h(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-intcharacter.h(9) : error C2062: type 'int' unexpectedcharacter.h(20) : error C2327: 'Character::DrawEngine' : is not a type name, static, or enumeratorGenerating Code...Compiling...main.cppcharacter.h(9) : error C2143: syntax error : missing ')' before '*'character.h(9) : error C2143: syntax error : missing ';' before '*'character.h(9) : error C2460: 'Character::DrawEngine' : uses 'Character', which is being definedcharacter.h(6) : see declaration of 'Character'character.h(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-intcharacter.h(9) : error C2062: type 'int' unexpectedcharacter.h(20) : error C2327: 'Character::DrawEngine' : is not a type name, static, or enumeratorGenerating Code...Compiling...game.cppcharacter.h(9) : error C2143: syntax error : missing ')' before '*'character.h(9) : error C2143: syntax error : missing ';' before '*'character.h(9) : error C2460: 'Character::DrawEngine' : uses 'Character', which is being definedcharacter.h(6) : see declaration of 'Character'character.h(9) : error C4430: missing type specifier - int assumed. Note: C++ does not support default-intcharacter.h(9) : error C2062: type 'int' unexpectedcharacter.h(20) : error C2327: 'Character::DrawEngine' : is not a type name, static, or enumeratorsucks because i have seen theres exactly the same and it compiles fine. so i don't understand why it isn't working.so any heads up would be great.and sorry if i am not allow to post this here.thank you for any help.[Edited by - Damnation on May 28, 2006 12:37:30 AM]
  Just add forward declaration for DrawEngine, before you start defining the Sprite or Character classes - there is no need to include DrawEngine.h in your Sprite.h (or so it looks to me).should be something like this:Sprite.h#ifndef SPRITE_H#define SPRITE_Henum{SPRITE_CLASSID,CHARACTER_CLASSID,};struct vector{float x;float y;};class DrawEngine;class Sprite{public:Sprite(DrawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);~Sprite();vector getPosition(void);float getX(void);float getY(void);virtual void addLives(int num = 1);int getLives(void);bool isAlive(void);virtual bool move(float x, float y);protected:DrawEngine *drawArea;vector pos;int spriteIndex;int numLives;int classID;vector facingDirection;void draw(float x, float y);void erase(float x, float y);};#endifCharacter.h#ifndef CHARACTER_H#define CHARACTER_H#include "sprite.h"class DrawEngine;class Character : public Sprite{public:Character(DrawEngine *de, int s_index, float x = 1, float y = 1, int lives = 3, char up_key = 'w', down_key= 's', char left_key = 'a', char right_key = 'd');virtual bool keyPress(char c);protected:char upKey;char downKey;char leftKey;char rightKey;};#endif;  i do need "DrawEngine.h" in Sprite.h because i define a DrawEngine pointer"protected:DrawEngine *drawArea;"the problem is, that sprite.h has a constructor:Sprite(DrawEngine *de, int s_index, float x = 1, float y = 1, int i_lives = 1);and i am overloading its constructor in character.hCharacter(DrawEngine *de, int s_index, float x = 1, float y = 1, int lives = 3, char up_key = 'w', down_key= 's', char left_key = 'a', char right_key = 'd');but it seems to me the compilier doesn't understand this. because when i go to doCharacter:: i get the sprites inherited class functions, and the characters function. BUT its constructor is not in the list, and obviously i get a ton of compile errors, all to do with that Constructor line.because in the compilers eyes it is not a constructor hense it moans about:error C4430: missing type specifier - int assumed. Note: C++ does not support default-intits really confusing i am using:Visual Studio pro 2005 as my ide.so any info as to why this is happening would rock.[edit] just to add, i did do the modifications your specified above, but they didn't work.1, because the need for the include in sprite.h.2, well i dunno still got that error and as of yet, i don't get it : o( ;  ok, i finally fixed this error. i did alot of google searching alot was about header files being included before the derived class, so the inheritance came from the base class, that wasn't my problem.what mine was (and what a stupid compile error) is i messed up in that line every time i typed it, i was tired shoot me!so basically i hadCharacter(DrawEngine *de, int s_index, float x = 1, float y = 1, int lives = 3, char up_key = 'w', down_key= 's', char left_key = 'a', char right_key = 'd');missing a char, on down_key.which gave me a not very helpful error.and other times problerly forgot a , but last night i just rushed the line.whereas this morning, i typed in each parameter and compiled. if it worked i'd then move onto the next, just hopeing to narrow down the problem.but hey its fixed now, so thank you for all you helpAdam   ;Quote:Original post by Damnationi do need "DrawEngine.h" in Sprite.h because i define a DrawEngine pointer"protected:DrawEngine *drawArea;"You don't need to include DrawEngine.h in Sprite.h, because you don't need details of implementation of DrawEngine class in Sprite.h - you are only using a pointer to it, you don't access any members.Forward declaration should be totaly enough. And in Sprite.cpp (or whatever file that implements Sprite methods) - you include the DrawEngine.h as usual.The same can be said about Character.h and Character.cpp (or whatever file that implements Character methods).However, Sprite class is a base class for Character class. This means, that Sprite.h MUST be included in Character.h and you can't get away with just a forward declaration of Sprite class.Hope it is more clear to you now.;  yes it is more clear to me now, thank you.i will take it into consideration, and fiddle around etc etc. also thanx to whoever edited my posts and did the source thing, now i've learnt how to put source code on these forums : o)thanx again Paulius Maruska the information was great.   