0

嗨,我的代码有问题。我收到错误 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();
}

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

4

2 回答 2

1

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

int *gamer; 

所以当你写

gamer->keyPress(key); 

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

你确定你想gamer成为一个int *?这似乎不正确。

于 2011-03-16T04:21:42.413 回答
0

改变

 int *gamer;

 Character* gamer;

 gamer; new Character(&drawArea, 0);

 gamer = new Character(&drawArea, 0);
于 2011-03-16T04:21:07.003 回答