gpt4 book ai didi

c++ - SDL C++ 类函数错误

转载 作者:太空宇宙 更新时间:2023-11-04 14:04:10 25 4
gpt4 key购买 nike

我在 main.cpp 中的代码片段

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()”的原型(prototype)与“playerEntity”类中的任何原型(prototype)都不匹配错误:候选者是:void playerEntity::handle()。我对头文件和类还不熟悉,如何修复错误?

最佳答案

你应该替换

playerEntity::handle()

void playerEntity::handle()

关于c++ - SDL C++ 类函数错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17736216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com