There's no fault.

Started by
10 comments, last by Spoonbender 17 years, 6 months ago
I don't understand this. I can't find any fault. The compiling errors:

Compiling...
Entities.cpp
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(9) : error C2629: unexpected 'class View ('
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(9) : error C2238: unexpected token(s) preceding ';'
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(11) : error C2061: syntax error : identifier 'Entity'
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(15) : error C2143: syntax error : missing ';' before '*'
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(15) : error C2501: 'Position' : missing storage-class or type specifiers
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(15) : error C2501: 'pTarget' : missing storage-class or type specifiers
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(25) : error C2065: 'Entity' : undeclared identifier
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(25) : error C2065: 'pEnt' : undeclared identifier
i:\projects\programming\klingis\1 body part\klingis\game\classes\view.h(25) : error C2182: 'InitView' : illegal use of type 'void'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.h(117) : error C2143: syntax error : missing ';' before '*'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.h(117) : error C2501: 'Entity' : missing storage-class or type specifiers
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.h(117) : error C2501: 'AddEntity' : missing storage-class or type specifiers
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(53) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'Sequence' (or there is no acceptable conversion)
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(54) : error C2679: binary '=' : no operator defined which takes a right-hand operand of type 'Frame' (or there is no acceptable conversion)
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(84) : warning C4244: '=' : conversion from 'double' to 'short', possible loss of data
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(85) : warning C4244: '=' : conversion from 'double' to 'short', possible loss of data
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(108) : error C2059: syntax error : '>'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(114) : error C2143: syntax error : missing ';' before '{'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(118) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(122) : error C2143: syntax error : missing ';' before '{'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(123) : error C2653: 'EntityVector' : is not a class or namespace name
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(124) : error C2653: 'EntityVector' : is not a class or namespace name
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(127) : error C2143: syntax error : missing ';' before '{'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(130) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(131) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(136) : error C2143: syntax error : missing ';' before '{'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(137) : error C2653: 'EntityVector' : is not a class or namespace name
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(138) : error C2653: 'EntityVector' : is not a class or namespace name
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(141) : error C2143: syntax error : missing ';' before '{'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(144) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(145) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(319) : error C2143: syntax error : missing ';' before '}'
i:\projects\programming\klingis\1 body part\klingis\game\classes\entities.cpp(319) : fatal error C1001: INTERNAL COMPILER ERROR

Entities.cpp

#include "Entities.h"
#include <Math.h>

///////////////////////////////////////////////////////////////


#define HALF_DIR_ANGLE		PI
#define FULL_DIR_ANGLE		(HALF_DIR_ANGLE * 2)
#define QUARTER_DIR_ANGLE	(HALF_DIR_ANGLE / 2)
#define EIGHT_DIR_ANGLE		(QUARTER_DIR_ANGLE / 2)


double dirAngle[NUM_DIRECTIONS] =
{
	0.0,								// _direction_up
	FULL_DIR_ANGLE - EIGHT_DIR_ANGLE,	// _direction_up_left
	FULL_DIR_ANGLE - QUARTER_DIR_ANGLE,	// _direction_left
	HALF_DIR_ANGLE + EIGHT_DIR_ANGLE,	// _direction_left_down
	HALF_DIR_ANGLE,						// _direction_down
	HALF_DIR_ANGLE - EIGHT_DIR_ANGLE,	// _direction_down_right
	QUARTER_DIR_ANGLE,					// _direction_right
	EIGHT_DIR_ANGLE						// _direction_right_up
};


///////////////////////////////////////////////////////////////

Entity::Entity(EntityDef *pDef, Uint32 x, Uint32 y, Uint8 dir)
{
	pEntDef = pDef;
	pos.x = x;
	pos.y = y;
	direction = dir;

}

/*
Entity::Entity(SDL_RWops *dataSrc)
{
	LoadData(dataSrc);
}
*/

void Entity::Update(void)
{
	if (animation == _animation_back && curFrame == 0)
	{
		animation = _animation_idle;
	}

	if (curSequence != preSequence) curFrame = 0;

	pSequence = pEntDef->pSequences[curSequence];
	pFrame = pSequence->pFrames[curFrame];

	switch (animation)
	{
	case _animation_loop:
		if (++curFrame >= pSequence->nFrames) curFrame = 0;
		break;
	case _animation_forth:
		if (curFrame < pSequence->nFrames - 1) curFrame++;
		break;
	case _animation_back:
		if (curFrame > 0) curFrame--;
		break;
	default:
		break;
	}

	pos.x += xmove;
	pos.y += ymove;

	xmove = 0;
	ymove = 0;
}




void Entity::Move(short step)
{
	double angle = dirAngle[direction];
	xmove = sin(angle) * step;
	ymove = cos(angle) * step;
}



void Entity::Draw(short x, short y)
{
	Bitmap *bmp = pFrame->one ?
	pFrame->dirs : pFrame->dirs + direction;
	DrawBitmap(bmp->pBitmaps,bmp->index,x-bmp->xOrigin,y-bmp->yOrigin);
}

///////////////////////////////////////////////////////////////

void DrawBitmap(Bitmaps *bmps, Uint8 index, short x, short y)
{

	DrawScreen(bmps->pSurface,bmps->pClips + index,x,y);
}

///////////////////////////////////////////////////////////////

#include <Vector>
typedef std::vector<Entity *> EntityVector;

EntityVector entities;


Entity *AddEntity(EntityDef *pDef, Uint32 x, Uint32 y, Uint8 dir)
{
	Entity *pEnt = new Entity(EntityDef *pDef, Uint32 x, Uint32 y, Uint8 dir);
	entities.push_back(pEnt);
	return pEnt;
}


void UpdateEntities(void)
{
	EntityVector::iterator cur = entities.begin();
	EntityVector::iterator end = entities.end();

	while (cur++ < end)
	{
		Entity *pEntity = *cur;
		pEntity->Update();
	}
}



void DrawEntities(View *pView)
{
	EntityVector::iterator cur = entities.begin();
	EntityVector::iterator end = entities.end();

	while (cur++ < end)
	{
		Entity *pEntity = *cur;
		pView->DrawEntity(pEntity);
	}
}

View.h

#ifndef _View_h
#define _View_h

#include "Screen.h"
#include "Entities.h"


class View {
	View(SDL_Rect *pFrm, Entity *pEnt);  // line: 9
	void Translate(void);
	void DrawEntity(Entity *pEnt);
	void Update(void);

	SDL_Rect *pFrame;
	Position *pTarget;
	Sint32 topEdgePos;
	Sint32 leftEdgePos;
	Uint32 rightEdgePos;
	Uint32 bottomEdgePos;
	Uint16 centerOffsetX;
	Uint16 centerOffsetY;
};


void InitView(Entity *pEnt);
void UpdateView(void);

#endif


Entities.h

#ifndef _Entities_h
#define _Entities_h

#include "Screen.h"
#include "View.h"


enum {
	_direction_up,
	_direction_up_left,
	_direction_left,
	_direction_left_down,
	_direction_down,
	_direction_down_right,
	_direction_right,
	_direction_right_up,
	NUM_DIRECTIONS
};


enum {
	_animation_idle,
	_animation_loop,
	_animation_forth,
	_animation_back,
	NUM_ANIMATIONS
};


typedef struct {
	SDL_Surface *pSurface;
	Uint8 nBitmaps;
	Uint8 xUnit;
	Uint8 yUnit;
	SDL_Rect *pClips;
//	BitMask *pBitMasks;
} Bitmaps;


void DrawBitmap(Bitmaps *bmps, Uint8 index, short x, short y);


typedef struct {
	Bitmaps *pBitmaps;
	Uint8 index;
	Uint8 xOrigin;
	Uint8 yOrigin;
} Bitmap;


typedef struct {
	bool one;
	Bitmap *dirs;	//[NUM_DIRECTIONS];
} Frame;


typedef struct {
	Frame *pFrames;
	Uint8 nFrames;
} Sequence;


struct EntityDefinition {
	Bitmaps *pBitmaps;
	Uint8 nBitmaps;
	Sequence *pSequences;
	Uint8 nSequences;
};

typedef struct EntityDefinition EntityDef;

/*
enum {
	_anim_dir_forwards,
	_anim_dir_backwards
};

enum {
	_animation_idle,
	_animation_loop,
	_animation_once
};
*/

typedef struct {
	Uint32 x;
	Uint32 y;
} Position;


class Entity {
	bool remove;
	EntityDef *pEntDef;
	Sequence *pSequence;
	Frame *pFrame;
	Uint8 curFrame;
	Uint8 preSequence;
	Uint8 curSequence;
	Uint8 direction;
	Uint8 animation;
//	Uint8 animdir;
	Position pos;
	short xmove;
	short ymove;

	Entity(EntityDef *pDef, Uint32 x, Uint32 y, Uint8 dir);
//	Entity(SDL_RWops *dataSrc);
//	bool LoadData(SDL_RWops *dataSrc);
//	bool SaveData(SDL_RWops *dataDst);
	Position *GetTarget(void);
	void Draw(short x, short y);
	void Move(short step);
	void Update(void);
};


Entity *AddEntity(EntityDef *pEntDef, Uint32 x, Uint32 y, Uint8 dir);
void UpdateEntities(void);
void DrawEntities(View *pView);

#endif


I tried to find the fault myself, but I can't find any fault. Please help.
Advertisement
My guess? You've left out a semicolon from a different include file, probably one that isn't shown here.

Your compiler provides an option to output the preprocessed source, with all the #includes included and all the #defines defined. This produces a hulking monstrosity of a file which is crucial for debugging many syntax errors which pop up at the beginning of header files or around heavy use of macros. Find the corresponding line in the preprocessed monstrosity (there are markers to help you) and see what the last few lines look like. My guess is, they will not all be kosher.
This is not your problem, but your classes are totally useless. They have no public interface! In C++ the default protection level is private. As you never over ride this with public, you cannot access your classes at all.

As to your errors, the first ones seem to be choking on the Entity in your view.h. You include entity.h so I don't know why that would happen. You could try putting a forward declaration of Entity in place of the #include though. Since you only reference pointers to Entities, this should suffice. You'd also need to do Position. Also, unless I'm wrong, you don't need to include Screen.h at all.

// View.h#ifndef _View_h#define _View_hstruct Position; // Forward declaration class Entity;    // Forward declaration...


Hope that helps in some way.
There's no fault, I'm #including Entities.h, it should work.
I'm including Entities.h, the Position and Entity
declarasion/definitions are there.
the fault is likely in screen.h post the code for that file. and stop saying "there is no fault". there is obviously a fault or the compiler wouldn't be erroring out. a good mantra is "the compiler is always right" (which is true 99.9999% of the time)

-me
The error is likely to be from 'screen.h', post that.
Also as Simian Man pointed out, your classes are not usable.
Consider what happens when a .cpp file include view.h (ignoring the screen.h file).
We first define _View_h, so from know on the contents of view.h can't be included.
We open the entities.h file, nothing in View.h have been declared yet, so no one knows about View. entities now tries to open view.h but fails to because _View_h is defined. We then proceed to parse the entities.h file even though we have never seen the View class. When we reach:
void DrawEntities(View *pView){	EntityVector::iterator cur = entities.begin();	EntityVector::iterator end = entities.end();	while (cur++ < end)	{		Entity *pEntity = *cur;		pView->DrawEntity(pEntity);	}}

We get a problem because we don't know about View yet. This is just one of the many problems and can be solved by using forward declarations.
Screen.h
#ifndef _Screen_h#define _Screen_h#include <SDL/SDL_video.h>bool CreateScreen(Uint8 directory);void FillScreen(void);void DrawScreen(SDL_Surface *surface, SDL_Rect *clip, short x, short y);void UpdateScreen(void);bool SaveScreenShot(char *filename);#endif
You need to forward declare Entity in the View.h header file. Don't #include "Entity.h" there, just forward declare the class:

class Entity;

-me
I get it now.

In Entities.h, View.h gets #included before the typedef structs and Entity class definations, and in Veiw.h when it #includes Entities.h _Entities_h are already defined so the #ifndef _Entities_h compile directive won't compile the content.

I get the problem now.
Am I right?

[Edited by - programering on September 29, 2006 12:05:26 AM]

This topic is closed to new replies.

Advertisement