1

g++ 似乎选择性地忽略了在类 Player 中声明的成员变量。它似乎也相信我的成员函数之一(void Player::update())被声明为虚拟的。我正在使用的库 (libtcod.hpp) 中声明的常量也没有通过,尽管在我所有其他类中都可以正常工作。这里有什么问题?

以下是 Player.cpp 附带的头文件:

#include "Map.h"
#include "Graphic.h"
#include "Dood.h"
#include "Villager.h"
#include "libtcod.hpp"

class Player: public Dood{
protected:
Graphic* rageGraphic;
TCODPath* myPath;
bool controlled;
void init(Graphic* _rage);
bool up, down, left, right;
static Player* myGuy;

public:
static Player* get();
Player(Graphic* _p);
Player(Graphic* _p, Graphic* _rage);
~Player();

void update();
void draw();
TCODPath* los(int x, int y);
};

这是我的错误代码:

Player.cpp:4: error: 'Player* Player::myGuy' is not a static member of 'class Player'
Player.cpp: In member function 'virtual void Player::update()':
Player.cpp:8: error: 'TCODConsole' has not been declared
Player.cpp:8: error: 'TCODK_UP' was not declared in this scope
Player.cpp:12: error: 'TCODConsole' has not been declared
Player.cpp:12: error: 'TCODK_DOWN' was not declared in this scope
Player.cpp:16: error: 'TCODConsole' has not been declared
Player.cpp:16: error: 'TCODK_LEFT' was not declared in this scope
Player.cpp:20: error: 'TCODConsole' has not been declared
Player.cpp:20: error: 'TCODK_RIGHT' was not declared in this scope
Player.cpp:30: error: 'myPath' was not declared in this scope
Player.cpp:69: error: 'class Map' has no member named 'getRealMap'
Player.cpp: In member function 'void Player::init(Graphic*)':
Player.cpp:103: error: 'myPath' was not declared in this scope
Player.cpp:103: error: expected type-specifier before 'TCODPath'
Player.cpp:103: error: expected ';' before 'TCODPath'
Player.cpp: In destructor 'Player::~Player()':
Player.cpp:119: error: 'myPath' was not declared in this scope
Player.cpp: At global scope:
Player.cpp:124: error: no 'Player* Player::get()' member function declared in class 'Player'`

编辑:这是 Player.cpp 的开头,大部分错误都在其中。

#include "Player.h"
#include <stdio.h>

Player* Player::myGuy = NULL;

void Player::update()
{
if(TCODConsole::isKeyPressed(TCODK_UP)){
    up = true;
}

if(TCODConsole::isKeyPressed(TCODK_DOWN)){
    down = true;
}

if(TCODConsole::isKeyPressed(TCODK_LEFT)){
    left = true;
}

if(TCODConsole::isKeyPressed(TCODK_RIGHT)){
    right = true;
}


if(++counter == max)
{
    counter = 0;

    if(controlled){
        if(myPath->isEmpty())
        {
            posn* temp = Map::get()->getRandomDestination();
            myPath->compute(x, y, temp->x, temp->y);
            printf("Destination set to (%d, %d)\n", temp->x, temp->y);
        }else{
            myPath->walk(&x, &y, false);
            printf("Proceeding to (%d, %d)\n", x, y);
        }
    }else{
        int tempY = 0;
        int tempX = 0;

        if(up){
            tempY -= 1;
        }

        if(down){
            tempY += 1;
        }

        if(left){
            tempX -= 1;
        }

        if(right){
            tempX += 1;
        }

        up = false;
        down = false;
        left = false;
        right = false;

        printf("Projected movement is (%d, %d)\n", tempX, tempY);

        tempX += x;
        tempY += y;

        if(Map::get()->getRealMap()->isWalkable(tempX, tempY)){
            x = tempX;
            y = tempY;
            printf("walking\n");
        }
    }
}

VillagerManager::get()->collide(x, y);
}
4

0 回答 0