Sign in to follow this  

Huh? It's telling me that I don't have what I have... weird. C++

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Look: CApp_Entity.h:14: error: expected class-name before '{' token Here is line #14: class Entity: public Sprite { Class name? Well, what does it think that 'Entity' is? C++, GCC, CodeBlocks, OpenGL, SDL.

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
is "Sprite" the name of a class you defined earlier, is it spelled/capped correctly?

Share this post


Link to post
Share on other sites
Is an Entity a Sprite, or is a Sprite an Entity? I've no idea how experienced you are but class declarations w/ inheritance should go like this:

class Square : public Shape (...)
class Triangle : public Shape (...)

Share this post


Link to post
Share on other sites
Quote:
Original post by Frequency
Is an Entity a Sprite, or is a Sprite an Entity? I've no idea how experienced you are but class declarations w/ inheritance should go like this:

class Square : public Shape (...)
class Triangle : public Shape (...)


Ummm.. Sprite is mostly 'Image', but has some cool things like rotation and stuff related to sprites... So, yeahh....

Here's the whole file:

#ifndef CAPP_ENTITY_H_
#define CAPP_ENTITY_H_

#pragma once

#include <list>

#include "CApp_Sprite.h"
#include "CApp_Event.h"
#include "CApp_Common.h"
#include "CApp_Vector.h"

namespace CApp {
class Entity: public Sprite {
private:
struct SStatus {
float Health;
float Attack;
float Defense;

int AttackType;

bool Alive;
};

protected:
int m_LastAttackTime;
int m_AttackDelayTime;

public:
Entity();
virtual ~Entity();

Vector3d Vel;
float RotVel;

SStatus Stats;

int Type;

virtual void Handle(Event &rEvent) = 0;
virtual void OnCollision(Entity *pWhat);

virtual Entity *Attack();
virtual bool MustAttack(std::list<Entity*> &rEntities, Event &rEvent);

virtual bool MustExplode();
};
};

#endif


Yes, I'm including CApp_Sprite.h...

Here it is:

#ifndef CAPP_SPRITE_H_
#define CAPP_SPRITE_H_

#include <SDL/SDL.h>

#include "CApp_List.h"
#include "CApp_Common.h"
#include "CApp_Vector.h"

#include <string>
using std::string;

#pragma comment(lib, "SDL_image.lib")

namespace CApp {
enum {
TO_RIGHT,
TO_LEFT
};

class Sprite {
public:
class CSurface {
public:
unsigned int Texture;

int Width, Height;

int r, g, b;

bool Load(const string &FileName);
bool Load(SDL_Surface *pSurface);
void UnLoad();
};

private:
struct SAnim {
CSurface Image;

int DelayTime;
};

List<SAnim, string> m_Animations;

int m_OldTime;

int m_IterDir;

List<SAnim, string>::Iterator m_Frame;

public:
Sprite();
~Sprite();

bool Has(const string &FileName) {
return m_Animations.Find(FileName);
}

string GetFrame();

int GetWidth(const string &FileName);
int GetHeight(const string &FileName);

//SDL_Rect GetRect(const string &FileName);

CSurface Sprite::GetSprite(const string &FileName) {
return (m_Animations[FileName].Image);
}

//void ReloadAll();

void AddAnim(const string &FileName, int r = 255, int g = 0, int b = 255);
void AddAnim(SDL_Surface *pSurface, const string &FileName, int r = 255, int g = 0, int b = 255);
void RemoveAnim(const string &FileName);

Vector3d Pos;
Vector3d Rad;
float Rot;

bool ToUpdate;

void Draw();

void UpdateFrame();

void SetDelay(int Delay, const string &FileName = "ALL");
void SetCurrentFrame(const string &FileName);
void SetDirection(int IterDir);

bool Collide(Sprite &rOther);
};
};

#endif


I have no idea what I'm doing wrong I've used sprite for so long now.

Share this post


Link to post
Share on other sites
it should read class Entity : public Sprite {... and NOT class Entity: public Sprite {... (note the space or the lack of it)

In the later case Entity: is interpreted as a label (as in "goto Entity;"), much like ">>" is interpreted as right bit shifting in vector<vector<int>> somevector.

Edit: Actually... I am wrong, this seems to work at least on g++ [embarrass]

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
it should read class Entity : public Sprite {... and NOT class Entity: public Sprite {... (note the space or the lack of it)

In the later case Entity: is interpreted as a label (as in "goto Entity;"), much like ">>" is interpreted as right bit shifting in vector<vector<int>> somevector.

Edit: Actually... I am wrong, this seems to work at least on g++ [embarrass]


Yeah, it works on GCC. I've actually never left a space between the name and ':' in any of my classes.

EDIT: I mean, the inheritance works, the problem still occurs.

Share this post


Link to post
Share on other sites
Quote:
Original post by Kwizatz
it should read class Entity : public Sprite {... and NOT class Entity: public Sprite {... (note the space or the lack of it)

In the later case Entity: is interpreted as a label (as in "goto Entity;"), much like ">>" is interpreted as right bit shifting in vector<vector<int>> somevector.

Edit: Actually... I am wrong, this seems to work at least on g++ [embarrass]


You have the right idea about how the lexer works, but AFAIK labels are recognized (as the two-token sequence of identifier and colon) at the parsing level, so that this is moot.

Share this post


Link to post
Share on other sites
Three things:
1 - namespace declarations don't have a semicolon after the closing brace (unlike class declarations, which do). I'm not sure if it makes any difference (I would've thought the compiler would parse the semicolon as an empty statement and not complain), but try removing them.

2 - Check CApp_Vector.h, very carefully (probably from the bottom up). If you have an error in that, it's conceivable that it might not be seen as an error until later.

3 - Maybe it isn't finding Sprite because of the namespaces? Try explicitly using class Entity : public CApp::Sprite (although given that you're in the CApp namespace when you declare Entity, I would expect what you've got to work... presumably you have other things of a similar form in other headers?)

John B

Share this post


Link to post
Share on other sites
My suggestion is to comment out the CApp namespace declarations and try compiling it that way, see what happens. I think the namespaces are confusing the compiler somehow...

Share this post


Link to post
Share on other sites
Quote:
Original post by JohnBSmall
Three things:
1 - namespace declarations don't have a semicolon after the closing brace (unlike class declarations, which do). I'm not sure if it makes any difference (I would've thought the compiler would parse the semicolon as an empty statement and not complain), but try removing them.

2 - Check CApp_Vector.h, very carefully (probably from the bottom up). If you have an error in that, it's conceivable that it might not be seen as an error until later.

3 - Maybe it isn't finding Sprite because of the namespaces? Try explicitly using class Entity : public CApp::Sprite (although given that you're in the CApp namespace when you declare Entity, I would expect what you've got to work... presumably you have other things of a similar form in other headers?)

John B


1) Check...
2) Check...
But just in case...

#ifndef CAPP_VECTOR_H_
#define CAPP_VECTOR_H_

namespace CApp {
class Vector3d {
public:
float x, y, z;

Vector3d(float x_ = 0.0f, float y_ = 0.0f, float z_ = 0.0f) {
x = x_;
y = y_;
z = z_;
}

Vector3d(const Vector3d &Vec) {
x = Vec.x;
y = Vec.y;
z = Vec.z;
}

Vector3d &operator =(const Vector3d &Vec) {
x = Vec.x;
y = Vec.y;
z = Vec.z;

return (*this);
}

bool operator !=(const Vector3d &Vec) {
return (x != Vec.x && y != Vec.y && z != Vec.z);
}

bool operator ==(const Vector3d &Vec) {
return !(this->operator !=(Vec));
}

bool operator <(const Vector3d &Vec) {
return (x < Vec.x && y < Vec.y && z < Vec.z);
}

bool operator >(const Vector3d &Vec) {
return (x > Vec.x && y > Vec.y && z > Vec.z);
}

Vector3d operator +(const Vector3d &Vec) {
Vector3d Temp;

Temp = (*this);

Temp.x += Vec.x;
Temp.y += Vec.y;
Temp.z += Vec.z;

return (Temp);
}

Vector3d &operator +=(const Vector3d &Vec) {
(*this) = (*this) + Vec;

return (*this);
}

Vector3d operator -(const Vector3d &Vec) {
Vector3d Temp;

Temp = (*this);

Temp.x -= Vec.x;
Temp.y -= Vec.y;
Temp.z -= Vec.z;

return (Temp);
}

Vector3d &operator -=(const Vector3d &Vec) {
(*this) = (*this) - Vec;

return (*this);
}

Vector3d operator *(const Vector3d &Vec) {
Vector3d Temp;

Temp = (*this);

Temp.x *= Vec.x;
Temp.y *= Vec.y;
Temp.z *= Vec.z;

return (Temp);
}

Vector3d &operator *=(const Vector3d &Vec) {
(*this) = (*this) * Vec;

return (*this);
}

Vector3d operator /(const Vector3d &Vec) {
Vector3d Temp;

Temp = (*this);

Temp.x /= Vec.x;
Temp.y /= Vec.y;
Temp.z /= Vec.z;

return (Temp);
}

Vector3d &operator /=(const Vector3d &Vec) {
(*this) = (*this) / Vec;

return (*this);
}

float GetCubedSize() {
return (x * x) + (y * y) + (z * z);
}
};
}

#endif


I don't see anything wrong.
3) Check...

Error... I have abosolutely NO idea why this is happenning. It worked until like... I move some movement into a class...

@iceman:
I don't see how namespaces would confuse the compiler, but it doesn't work that way either.

I'm all out of ideas! I don't want to abandon this beautiful project!

Share this post


Link to post
Share on other sites
Another thing to check is make sure the include guard CAPP_SPRITE_H_ isn't being used by any other headers. I've had this happen to me a couple of times by copying-and-pasting a base class to use as a starting point for writing the derived class.

Share this post


Link to post
Share on other sites
Quote:
Original post by joanusdmentia
Another thing to check is make sure the include guard CAPP_SPRITE_H_ isn't being used by any other headers. I've had this happen to me a couple of times by copying-and-pasting a base class to use as a starting point for writing the derived class.


Check.
Nope, still occurs!

What can it possibly want so much? This code has been this way for like... ever! And NOW it doesn't work!

EDIT: I even created a new project and cleaned and rebuilt and STILL THE SAME ERROR!
EDIT: It recognizes other classes, like Engine, but then it tell's me it can't find the variables... well, duh. But, IT WILL NOT RECOGNIZE SPRITE!

[Edited by - agi_shi on January 28, 2006 7:51:16 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
What was the last change you did to your project before this error popped up? Or what does this mean "It worked until like... I move some movement into a class..."

Try commenting out the CSurface class in CApp_Sprite.h and recompile?

Also, I believe, you can remove the includes, CApp_Common.h and CApp_Vector.h, from the Entity header file since those are included in the Sprite header file.

Share this post


Link to post
Share on other sites
Thanks guys, but I got it working. It was including 1->2->3->1 and so on, which gave the error.

Commenting out the Entity include from CApp_Common and using a forward declaration fixed it.

Share this post


Link to post
Share on other sites

This topic is 4337 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this