C++ SDL Expected unqualified-id before '-' token -


i have used:

typedef struct entity {     int health;     int damage;     sdl_rect hitbox; } player, basicenemy[10]; 

to handle player (and enemies). problem get:

error: expected unqualified-id before '-' token 

for line (and 1 similiar):

if( keystate[sdlk_left] )  player.hitbox.x -= 1; 

how fix this? if don't have typedef on struct error doesn't occur, 1 (which why made have typedef)

headers:

#include "sdl.h" #include "sdl\sdl.h" #include <string> 

typedef defines type alias. saying:

typedef struct entity {     // ... } player, basicenemy[10]; 

you saying:

struct entity {     // ... };  typedef entity player;          // 'player' alias 'entity'. typedef entity basicenemy[10];  // 'basicenemy' alias 'entity[10]'. 

when mean make struct declaration , 2 instance definitions:

struct entity {     // ... } player, basicenemy[10]; 

it may better separate them, avoid potential confusion:

struct entity {     // ... };  entity player, basicenemy[10]; 

note semicolon required after struct declaration when makes no instance definitions.


Comments

Popular posts from this blog

php - Calling a template part from a post -

Firefox SVG shape not printing when it has stroke -

How to mention the localhost in android -