Sign in to follow this  
Miles Lombardi

My class going haywire

Recommended Posts

I have a class called Sprite. It was called SPRITE but then after some advice i renamed it Sprite. Then all of a sudden it went a little haywire. This topics gonna have a few bugs in it, because some more cropped up when I tried to rebuild all. And without eradicating the ones in a certain .cpp I can't show you the ones in the others. Anyway, Current Bug:
Quote:
In file included from link.h:5, from vardec.h:8, from main.cpp:7: sprite.h:20: error: `sbuffer' was not declared in this scope
That's a little odd, I thought. I'll show you the lines it's going through link.h:5 - #include "sprite.h" vardec.h:8 - #include "link.h"0 main.cpp:7 - #include "vardec.h" sprite.h:20 - void draw(int x, int y, int frame, BITMAP * destination = sbuffer); So that's where it got the sbuffer from. But then I get confused. Because in vardec.h (#include'd at line 7 of main.cpp) at line 17 I set sbuffer (a BITMAP*) as extern. And then I declare it in line 23 of main.cpp locally (just BITMAP * sbuffer). Seeing as vardec.h isn't that important really here's the source:
//vardec.h
#ifndef VARDEC_H_INC
#define VARDEC_H_INC
#define ROOM_EXIT 0
#define ROOM_TITLE 1
#define ROOM_HELMAROC 2
#include <allegro.h>
#include "link.h"
#include "helmaroc.h"
#include "room.h"

extern bool B2S;
extern bool run;

extern BITMAP *title_screen;
extern BITMAP *press_start;
extern BITMAP *sbuffer;
extern BITMAP *tower;
extern BITMAP *rock;

extern int stepcounter;
extern int room;

extern int heartcontainers;
extern int hearts;

extern int view_x;
extern int view_y;

extern bool col_tower[67][54];

extern OBJ_LINK *link;
extern OBJ_HELMAROC *helmaroc;
extern clROOM *rmtower;

#endif


Oh and before I forget the next bug was something like " Sprite spr_helmaroc_left; Sprite does not name a type". And this is in the header...

Share this post


Link to post
Share on other sites
The problem is your include order. If you manually expand the files (just like the preprocessor does) it becomes clear (extra whitespace added for extra clarity):
/* vardec.h */
#ifndef VARDEC_H_INC
#define VARDEC_H_INC
#define ROOM_EXIT 0
#define ROOM_TITLE 1
#define ROOM_HELMAROC 2
#include <allegro.h>
//#include "link.h"
/* link.h */
// ...
//#include sprite.h
/* sprite.h */
// ...
/* this is the problem */
void draw(int x, int y, int frame, BITMAP * destination = sbuffer);
// ...
// ...
// ...
/* now sbuffer is declared */
extern BITMAP *sbuffer;
// ...

sbuffer is declared after it is used. You need to reorder your includes so that it is declared before it is used.

Enigma

Share this post


Link to post
Share on other sites
Well enigma after a little work I figured it out.
It actually went
extern BITMAP * sbuffer;
void draw(etc);
BITMAP * sbuffer

Anyway to my new problems
helmaroc.h:20: error: `Sprite' does not name a type
helmaroc.h:21: error: `Sprite' does not name a type
helmaroc.h:22: error: `Sprite' does not name a type

Lines:
Sprite spr_helmaroc_left;
Sprite spr_helmaroc_right;
Sprite sprite_index;

I'm not entirely sure why it would do this, so could someone just please explain what the error means? Because I can guarantee that's not enough code for you to sort it.

So to be nice, here's sprite.h:


class Sprite {
public:
int offset_x;
int offset_y;
int max_frames;
int width;
int height;
int id;
bool operator == (Sprite &class1);
BITMAP ** frames;
Sprite(BITMAP * load_sprite, int load_width, int load_height, int frame_num, int load_offset_x = 0, int load_offset_y = 0, int offset_x = 0, int offset_y = 0);
~Sprite();
void draw(int x, int y, int frame, BITMAP * destination);

};

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
This isn't related to the current problem, but I'd advise you to define an assignment operator and copy constructor for class Sprite, seeing how it contains dynamic data (in the form of BITMAP**).

Share this post


Link to post
Share on other sites

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