gpt4 book ai didi

C++ 错误 1 ​​错误 C2227 : left of '->keyPress' must point to class/struct/union/generic type

转载 作者:行者123 更新时间:2023-11-28 08:22:25 24 4
gpt4 key购买 nike

您好,我的代码有问题。我收到错误 C2227。

我的代码:

游戏.h

#ifndef GAME_H
#define GAME_H
#include "drawEngine.h"
#include "Sprite.h"


class Runner
{
public:
bool run();



Runner(){};
protected:
bool getInput(char *c);

void timerUpdate();
private:
int *gamer;
double frameCount;
double startTime;
double lastTime;

int posX;



drawEngine drawArea;
};

#endif

游戏.cpp

#include "Game.h"
#include <conio.h>
#include <iostream>
#include "drawEngine.h"
#include "Character.h"
#include <windows.h>
using namespace std;
//this will give ME 32 fps
#define GAME_SPEED 25.33
bool Runner::run()
{

drawArea.createSprite(0, '$');
gamer; new Character(&drawArea, 0);


char key = ' ';

startTime = timeGetTime();

frameCount = 0;
lastTime = 0;

posX = 0;

while (key != 'q')
{
while(!getInput(&key))
{
timerUpdate();
}

gamer->keyPress(key);
//cout << "Here's what you pressed: " << key << endl;
}

delete gamer;
cout << frameCount / ((timeGetTime() - startTime) / 100) << " fps " << endl;
cout << "Game Over" << endl;

return true;
}

bool Runner::getInput(char *c)
{
if (kbhit())
{
*c = getch();
return true;
}
}

void Runner::timerUpdate()
{
double currentTime = timeGetTime() - lastTime;

if (currentTime < GAME_SPEED)
return;


frameCount++;

lastTime = timeGetTime();
}

我以前从未见过这个。我到处寻找答案,但它们不适用于我的代码。我还有其他代码属于我没有发布的同一项目。

最佳答案

我认为问题在于您将 gamer 定义为

int *gamer; 

所以当你写的时候

gamer->keyPress(key); 

您正试图在 int 上调用成员函数,这是不合法的。

您确定要将 gamer 设为 int * 吗?这似乎不正确。

关于C++ 错误 1 ​​错误 C2227 : left of '->keyPress' must point to class/struct/union/generic type,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5320958/

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