Jump to content
  • Advertisement
Sign in to follow this  
nullsquared

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

This topic is 4617 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
Advertisement
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
I suppose the errormessage relates to the class Sprite. Mybe you forgot to include the header for the class Sprite?

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
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.

Share this post


Link to post
Share on other sites
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.

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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!