從main.cpp中的我的代碼片段的SDL C++類功能錯誤
playerEntity::handle()
{
if(event.type == SDL_KEYDOWN)
{
switch(event.key.keysym.sym)
{
case SDLK_q:
running = false;
paused = true;
break;
case SDLK_ESCAPE:
paused = !paused;
break;
}
}
if(keystate[SDLK_UP])
{
if(isJumping == false && isFreeFalling == false)
{
isJumping = true;
}
}
if(keystate[SDLK_LEFT]) player.hitbox.x--;
if(keystate[SDLK_RIGHT]) player.hitbox.x++;
if(player.hitbox.x < 0) {player.hitbox.x = 0;}
else if(player.hitbox.x > screen.WIDTH - player.hitbox.w) {player.hitbox.x = screen.WIDTH - player.hitbox.w;}
if(player.hitbox.y < 0) {player.hitbox.y = 0;}
else if(player.hitbox.y > screen.HEIGHT - player.hitbox.h) {player.hitbox.y = screen.HEIGHT - player.hitbox.h;}
}
凡playerEntity
在頭文件中被定義:
#ifndef PLAYERENTITY_H
#define PLAYERENTITY_H
class playerEntity
{
private:
int jumpHeight;
int jump;
bool isJumping;
bool isFalling;
bool isFreeFalling;
SDL_Event event;
Uint8 *keystate;
public:
playerEntity();
void jump();
void handle();
void fall();
int health;
int damage;
SDL_Rect hitbox;
bool evolved;
};
#endif
當我嘗試編譯我得到的錯誤: ISO C++禁止聲明沒有類型的'句柄'[-fpermissive] 'int playerEntity :: handle()'的原型不匹配'playerEntity'中的任何類型 error:candidate is:void playerEntity :: handle )。 我對頭文件和類還不熟悉,我該如何解決這些錯誤?