【发布时间】:2015-05-03 16:53:07
【问题描述】:
所以,我遇到了一个可能很简单的问题,但我似乎无法弄清楚是什么原因造成的。
我有一个名为“Game”的 C++ 类,由 Game.h 中的类声明组成 以及 Game.cpp 中的源定义。
我已在“Game.cpp”中包含“Game.h”,但由于某种原因,Visual Studio 似乎无法识别 Game.h 中的类声明。
如果我能得到任何帮助来弄清楚为什么会出现这种情况,以及为什么会出现以下错误,我将不胜感激:
'MyCharacter' : undeclared identifier 和 'HandleKeyPressed' : identifier not found。
游戏.h:
------------------------------------------------------------------------------------------------------------------
#pragma once
#ifndef Game_Header
#define Game_Header
#include <SFML/Graphics.hpp>
#include <SFML/Audio.hpp>
#include "Character.h"
#include "FloorPlatform.h"
class Game
{
public:
Game();
~Game();
int Run();
void HandleKeyPressed(sf::Keyboard::Key);
Character MyCharacter;
};
#endif // !Game_Header
Game.cpp 精简版
#include "Game.h"
Game::Game()
{
}
Game::~Game()
{
}
int Run(){
sf::RenderWindow MainGameWindow(sf::VideoMode::getDesktopMode(), "A Test Game");
//Start Game Loop
while (MainGameWindow.isOpen()){
while (MainGameWindow.pollEvent(event)){
//Handle some other events here...
if (event.type == sf::Event::KeyPressed){
HandleKeyPressed(event.key.code);
}
}
MainGameWindow.clear(sf::Color::White);
MyCharacter.Instance.Circle.setPosition(MyCharacter.PlayerLocation);
MainGameWindow.draw(MyCharacter.Instance.Circle);
MainGameWindow.display();
}
return 0;
}
void HandleKeyPressed(sf::Keyboard::Key PressedKey){
switch (PressedKey)
{
case sf::Keyboard::A:
MyCharacter.PlayerLocation.x -= 16;
break;
}
}
完整的代码可以在这里找到: http://pastebin.com/x6KhDxgL
在此先感谢您提供的任何帮助。
【问题讨论】:
标签: c++ header identifier undeclared-identifier