2013-07-08 2 views
1

이 코드를 컴파일 할 때 다음 오류가 발생합니다. 그 이유는 무엇입니까?C++ struct에 형식 오류의 이름이 지정되지 않았습니다.

'game.h : 48 : 42 : 오류 :'플레이어 '유형을

game.h 이름없는 : 48 : 50 : 오류 : ISO C++가없는 타입 [와'적 '의 선언을 금지 - player는 형태가 아니기 때문에 fpermissive] "BTW

//game.h 

#ifndef GAME_H 
#define GAME_H 

//CONSTANTS AND TEMPLATES 

const int LEN = 40; 

struct player 
{ 
    char name[LEN]; //name of character 
    char symbol; //character representing player on map 
    int posx; // x position on map 
    int posy; // y position on map 
    bool alive; // Is the player alive 
    double damage; // Player attacking power 
    double health; // Player health 
}; 

enum direction {LEFT, RIGHT, UP, DOWN}; 

//PROTOTYPES 

//move amount specified in position structure 
void moveAmount(player& pl, int posx, int posy); 

//move to specified position on map 
void moveTo(player& pl, int posx, int posy); 

//one player attacking other 
//returns whether attack was successfull 
bool attack(const player & atacker, player & target); 

//one player attacking a direction on the map, epl is a pointer to an array of enemies   players 
//returns whether attack was sucessfull 
bool attack(const player & pl, direction, player* epl); 

//Check if player is dead, to be called inside attack function 
inline bool isDead(const player& pl){ 
    return pl.health <= 0 ? 1 : 0; 
} 

//Remove player from map if he is dead 
void kill(player& pl); 

//Initialize map 
void fillMap(const player& player, const player* enemies, int mapWidth, int mapHeigth); 

//Display map 
void displayMap(const int mapWidth, const int mapHeigth); 

#endif 
+3

귀하의 변수는 – jogojapan

답변

4

문제는이 라인에 : 매개 변수로 player를 선언하기 때문에, 전체 앞으로 선언의 범위를 유지

void fillMap(const player& player, const player* enemies, int mapWidth, int mapHeigth); 

. 따라서 그 이름은 형식 이름 player을 음영 처리합니다. fillMap의 전방 선언 내에서 playerplayer 유형이 아니라 첫 번째 매개 변수를 나타냅니다.

이 문제를 해결하기 위해 pl로 이름을 바꿉니다

void fillMap(const player& pl, const player* enemies, int mapWidth, int mapHeigth); 
+0

아 ... 간단합니다 ... 고마워요! –

-1

fillMap"

라인 (48)은 함수 "; struct player입니다.

+2

물론'player'이 유형의 이름 같은 이름 유형으로 ('player'를) ... 있습니다. 그러나 그 이름은 변수 이름에 의해 숨겨져 있습니다. – jogojapan

관련 문제