g ++选择性地忽略成员声明

时间:2013-01-26 20:48:44

标签: c++ g++

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);
}

0 个答案:

没有答案