C++ C++;错误 ;1错误C2227:x27左侧-&燃气轮机;按键';必须指向类/结构/联合/泛型类型

C++ C++;错误 ;1错误C2227:x27左侧-&燃气轮机;按键';必须指向类/结构/联合/泛型类型,c++,windows,visual-c++-2008,C++,Windows,Visual C++ 2008,嗨,我的代码有问题。我得到错误C2227 我的代码: Game.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 *

嗨,我的代码有问题。我得到错误C2227

我的代码:

Game.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
Game.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();
}
#包括“Game.h”
#包括
#包括
#包括“paurengine.h”
#包括“Character.h”
#包括
使用名称空间std;
//这将给我32 fps
#定义游戏速度25.33
bool Runner::run()
{
createSprite(0,“$”);
玩家;新角色(&drawArea,0);
字符键=“”;
startTime=timeGetTime();
帧数=0;
lastTime=0;
posX=0;
while(键!=“q”)
{
while(!getInput(&key))
{
timerUpdate();
}
玩家->按键(键);
//不能改变


我认为问题在于你把玩家定义为

int *gamer; 
所以当你写作的时候

gamer->keyPress(key); 
您试图在
int
上调用成员函数,这是不合法的


你确定你想让玩家成为
int*
?这似乎不正确。

它给了我一个新的错误:C2440:“=”:无法从“Character*”转换为“int*”啊,你需要在Runner类之前声明Character类-添加一行“class Character;”就在game.h..中它之前,或者在game.cpp中包含Character.h before game.h如果没有其他依赖项或者我没有看到该注释,它会给我一个新错误:C2541:“delete”:无法删除不依赖的对象pointers@Blackelfwolf-你把它改成了什么?如果你想
删除它,请确保它是一个指针。@Blackelfwolf-我认为你需要坐下来重新思考你的设计。不要只是尝试做这样的小改动。如果你试图使用
gamer
作为可以响应
gamer->keyPress(键)的东西
,它应该是什么类型?花些时间思考一下你的设计应该是什么;只是试图通过这些本地化的更改来编译它,这会掩盖高级设计问题,可能会给你留下一个非常不起作用的系统。实际上,我是通过3d Bu上一个名为邪恶猴子的教程来完成这项工作的zz网站。
 gamer; new Character(&drawArea, 0);
 gamer = new Character(&drawArea, 0);
int *gamer; 
gamer->keyPress(key);