Mail Archives: djgpp/1997/09/01/13:47:44
Mark Augustyn <augustyn DOT 3 AT osu DOT edu> wrote in article
<340A0B24 DOT 55B6E7F7 AT osu DOT edu>...
> I hate to ask a dumb question but is this the appropriate way to declare
> a struct:
>
> struct cell {
> int terrain;
> BITMAP *tile;
> };
>
> It seems simple enough, however, I get the following error when I
> declare a variable to be of type cell:
> Line 16:
> cell map;
>
I am assuming you are compiling this as C, not C++.
In this case, you need to specify that cell is a struct:
struct cell map;
Otherwise the compiler has no way to know what 'cell' is.
You could also use a typedef as below:
typedef struct {
int terrain;
BITMAP *tile;
} cell;
cell map;
but in my opinion, it is a wiser idea to use the first method.
This way, you will always know that map is in fact a struct,
and not a typedef'd union or simple type. Which can help avoid many
problems when a project gets large, or you've been away from it for
a long time. (typos are the #1 bug producers, right before
uninitialized pointers IMO).
>
> What am I missing? Do I need to include something to use structs and
> classes?
structs and classes are similar, but they are not the same thing.
Just remember to call a struct a struct, and you should be fine.
Good luck.
--------------------
George Kinney
gkinney (AT) usa (DOT) net
- Raw text -