Huh? It's telling me that I don't have what I have... weird. C++
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.
I suppose the errormessage relates to the class Sprite. Mybe you forgot to include the header for the class Sprite?
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 (...)
class Square : public Shape (...)
class Triangle : public Shape (...)
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.
You have an anonymous enumeration right before your Sprite class. While legal under C++, some compilers struggle with them. Try naming your enumeration and recompiling.
Changed it to const ints and it still does the same thing.
Anyways, I have TONS of unnamed enums all over my code.
Anyways, I have TONS of unnamed enums all over my code.
It didn't tell me anything when I just commented out the ":public Sprite" part...
EDIT: Other than telling me that 'this->' doesn't have everything relating to Sprite.
EDIT: Other than telling me that 'this->' doesn't have everything relating to Sprite.
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]
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]
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement