2012-04-03 56 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