zero size array declaration

Hi, I am working on a project using c++/allegro and allegro has a struct call BITMAP to work with bitmaps. The bitmap structure for reference:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
typedef struct BITMAP            /* a bitmap structure */
{
   int w, h;                     /* width and height in pixels */
   int clip;                     /* flag if clipping is turned on */
   int cl, cr, ct, cb;           /* clip left, right, top and bottom values */
   GFX_VTABLE *vtable;           /* drawing functions */
   void *write_bank;             /* C func on some machines, asm on i386 */
   void *read_bank;              /* C func on some machines, asm on i386 */
   void *dat;                    /* the memory we allocated for the bitmap */
   unsigned long id;             /* for identifying sub-bitmaps */
   void *extra;                  /* points to a structure with more info */
   int x_ofs;                    /* horizontal offset (for sub-bitmaps) */
   int y_ofs;                    /* vertical offset (for sub-bitmaps) */
   int seg;                      /* bitmap segment */
   ZERO_SIZE_ARRAY(unsigned char *, line);
} BITMAP;


So now I am trying to create a structure with inheritance to BITMAP to manage menu items such as certain words in the font I want assorted around the screen to make a pause menu. (if there is a better way to do the menus, criticism welcome :) but thats another topic) So for lets say the pause menu I want to create a struct:
1
2
3
4
5
struct PAUSEMENU : BITMAP
{
int x, y;
etc..
}PAUSEMENU;


but when I run it an error comes up:

error C2503: 'BITMAP' : base classes cannot contain zero-sized arrays

What is the reason they put in the zero size array? Is there any way I can inherit properties of BITMAP to another class?

Thank you,
Ed
Don't use C types (such as the one above) as base classes. They won't be properly cleaned up when the derived instance is destructed.
I suspect that macro was put there intentionally to prevent unwitting users from deriving from the struct.

Instead of deriving, create members of that type in the class.

Oh, and your struct declaration will be rejected by some compilers. You're basically doing this:
1
2
struct PAUSEMENU{/*...*/};
PAUSEMENU PAUSEMENU;
This effectively makes referring to the PAUSEMENU type impossible after the class definition because the PAUSEMENU object will have hidden it, which means you can't pass parameters of that type, create new instances, etc. etc.

And finally, try to avoid declaring fully capitalized identifiers that aren't macros or constants. People usually expect such identifiers to refer to either of those, so your style could be confusing. Also, fully capitalized identifiers are more likely to create conflicts when someone has already declared a macro with the same name.
The opposite also applies, but even more strongly. Don't declare macros in all lower case. People don't expect them to be macros.
Last edited on
thanks a lot @helios

I really do appreciate it.

I will create members inside of the class and do it that way, as well as the other things you mentioned about c types. Also thanks for the tips about style and such, every bit helps.

EDIT:

Okay yeah, that worked a lot better, and is much more simple. Thanks for the help
Last edited on
Topic archived. No new replies allowed.