-1

これは構文エラーのある私のコードです。

struct cell{
        bool in;
        bool up;
        bool left;
        int prevx, prevy;
};
cell MAZE[xsize][ysize];

このコードは、「セル」行でこのエラーを返します。

error: expected ‘=’, ‘,’, ‘;’, ‘asm’ or ‘__attribute__’ before 'MAZE'

私の間違いを指摘してもらえますか?

4

3 に答える 3

10

The correct way to declare the struct is:

struct cell MAZE[xsize][ysize];

You can also do this:

typedef struct {
    bool in;
    bool up;
    bool left;
    int prevx, prevy;
} cell;

cell MAZE[xsize][ysize];
于 2012-10-31T17:44:02.833 に答える
2

In C, you have to write:

struct cell MAZE[xsize][ysize];

In C++, there's an 'automatic typedef', but not in C.

You could also write:

typedef struct cell cell;

Then your declaration (not initialization) would be correct.

Usually, all-caps names such as MAZE are reserved for macros in C.

于 2012-10-31T17:44:31.127 に答える
1

これもできます。

struct cell{
        bool in;
        bool up;
        bool left;
        int prevx, prevy;
}MAZE[xsize][ysize];
于 2012-10-31T17:51:10.043 に答える