2012-04-03 52 views
1

我想用SFML做一个简单的程序。到目前为止,我有一个主文件和一个文件来打开窗口,以及该文件的头文件。事情是,我已经受够了头一个问题:预期的不合格ID在标题C++

#ifndef Window.hpp 
#define Window.hpp 

Window(); 
int Loop(); 

#endif 

我得到这个错误:

C:\ Window.hpp |错误| 4:之前预期不合格的ID”。 “令牌|

窗口的文件是:

#import <SFML/Window.hpp> 
#import <iostream> 

// This file needs to create and maintain the program's window, and change it's state. 

class Window 
{ 
sf::RenderWindow appWindow; 
sf::Image charImage; 
sf::Sprite charSpriteSheet; 

public: 
Window(); 
int Loop(); 
} 

Window::Window() 
{ 
appWindow.Create(sf::VideoMode(800, 600, 32), "AI_Fighter"); 
if(!charImage.LoadFromFile("Bass.png")) 
{ 
    cout << "Problem opening file 'Bass.png'"; 
} 

charSpriteSheet.SetImage(charImage); 
} 

int Window::Loop() 
{ 
    // Start game loop 
while (appWindow.IsOpened()) 
{ 
    sf::Event evt; 
    while (appWindow.GetEvent(evt)) 
    { 
     // Window closed 
     if (evt.Type == sf::Event::Closed) 
      appWindow.Close(); 

     // Escape key pressed 
     if ((evt.Type == sf::Event::KeyPressed) && (evt.Key.Code == sf::Key::Escape)) 
      appWindow.Close(); 
    } 

    // Get elapsed time 
    float ElapsedTime = appWindow.GetFrameTime(); 

    // Move the sprite 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Left)) charSpriteSheet.Move(-100 * ElapsedTime, 0); 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Right)) charSpriteSheet.Move(100 * ElapsedTime, 0); 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Up)) charSpriteSheet.Move(0, -100 * ElapsedTime); 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Down)) charSpriteSheet.Move(0, 100 * ElapsedTime); 

    // Rotate the sprite 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Add))  charSpriteSheet.Rotate(-100 * ElapsedTime); 
    if (appWindow.GetInput().IsKeyDown(sf::Key::Subtract)) charSpriteSheet.Rotate(100 * ElapsedTime); 

    // Clear the screen (fill it with black color) 
    appWindow.Clear(sf::Color(0, 0, 0)); 

    appWindow.Draw(charSpriteSheet); 

    // Display window contents on screen 
    appWindow.Display(); 
} 
} 
+0

我不认为'.'被允许在'#define'常量。 – RedX 2012-04-03 13:51:16

回答

3

更改您的代码:

#ifndef Window.hpp 
#define Window.hpp 

#ifndef Window_hpp 
#define Window_hpp 
+1

失踪“;”在Window :: Window()之前关闭该类。 – 2012-04-03 14:06:11

+0

修复已经...但是我仍然得到C:\ ... \ Window.hpp | 4 |错误:预期的构造函数,析构函数或类型转换之前';'令牌| – MKII 2012-04-03 14:13:33

+0

在哪条线上出现错误? – 2012-04-03 14:32:31