Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: multiple types in one declaration

Tags:

c++

codeblocks

I am using Code::Blocks and Mingw32 with the SDL libraries. The error appears at line 13 of my code (commented below).

After some searching I believed it to be a missing semicolon(;), this doesn't appear to be the case here though. Additional research threw up the fact that it may be an error in an include file.

Unfortunately there are no errors in the includes and even when the include is commented out this error persists. When the enum block is commented out the error jumps to the end of the class declaration.

#ifndef _TILE_H_
#define _TILE_H_

#include "Define.h"

enum
{
    TILE_TYPE_NONE = 0,
    TILE_TYPE_GROUND,
    TILE_TYPE_RAMPUP,
    TILE_TYPE_RAISED,
    TILE_TYPE_RAMPDOWN
}; //error occurs here (line 13)

class Tile
{
public:
    int TileID;
    int TypeID;

public:
    Tile();
};

#endif

This actually started happening after adding a new class, however the new class is completely unrelated and does not use, include or inherit from the posted one at all.

Any advice or information would be really appreciated.

EDIT (adding Define.h):

#ifndef _DEFINE_H_
#define _DEFINE_H_

#define MAP_WIDTH 40
#define MAP_HEIGHT 40

#define TILE_SIZE 16

#define WINDOW_WIDTH 640
#define WINDOW_HEIGHT 480

#endif
like image 676
ChrisGuy Avatar asked May 11 '26 19:05

ChrisGuy


1 Answers

You have a file with this:

#include "Something.h"
#include "Tile.h"

In Something.h, you have this:

class Something {
    // ...
}

You are missing a semicolon, so the compiler sees:

class Something {
    // ...
}
enum {
};

Which is one declaration containing two types (a class and an enum), which is not allowed. The semicolon is required after class, struct, and enum because you can declare instances of a new type in the same declaration as the type:

struct Point { int x; int y; } my_point;

(Also, names starting with _ and a capital letter are reserved. Use TILE_H instead of _TILE_H_.)

like image 117
Jon Purdy Avatar answered May 14 '26 10:05

Jon Purdy



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!