C++ SDL_Rect inside a struct: Does not name a type

2019-09-09 05:41发布

问题:

I am making a basic game and to make things easier I have used:

struct entity {
    int health;
    int damage;
    SDL_Rect hitbox;
} player, basicEnemy[10];

But when I call:

player.hitbox.x = 5;

or something similiar, I get the error:

'player' does not name a type

How do I fix this?

回答1:

Add typedef in front of the key word struct.



标签: c++ struct sdl