2011-08-30 60 views
0

我的代碼無法編譯。我究竟做錯了什麼?我還希望sf::Windowsf::Input對象是靜態字段。什麼是最好的方式去做這件事?編譯器錯誤'NonCopyable :: NonCopyable(const NonCopyable&)'是私人的

#include <SFML/Window.hpp> 
#include <SFML/Window/Event.hpp> 
#ifndef WINDOW_INITIALIZER_H 
#define WINDOW_INITIALIZER_H 

class WindowInitializer 
{ 
public: 
    WindowInitializer(); 
    ~WindowInitializer(); 

private: 
    void initialize_booleans(const sf::Window * const app); 

    bool m_leftKeyPressed; 
    bool m_rightKeyPressed; 
    bool m_upKeyPressed; 
    bool m_downKeyPressed; 

    unsigned int m_mouseX; 
    unsigned int m_mouseY; 
}; 

#endif // WINDOWINITIALIZER_H 

void WindowInitializer::initialize_booleans(const sf::Window* const app) 
{ 

    sf::Input input = app->GetInput(); 

    this->m_downKeyPressed = input.IsKeyDown(sf::Key::Down); 
    this->m_leftKeyPressed = input.IsKeyDown(sf::Key::Left); 
    this->m_upKeyPressed = input.IsKeyDown(sf::Key::Up); 
    this->m_rightKeyPressed = input.IsKeyDown(sf::Key::Right); 

    this->m_mouseX = input.GetMouseX(); 
    this->m_mouseY = input.GetMouseY(); 
} 

WindowInitializer::WindowInitializer() 
{ 
    sf::Window app(sf::VideoMode(640, 480, 32), "SFML Tutorial"); 

    initialize_booleans(&app); 

    sf::Event event; 

    while(app.IsOpened()) 
    { 
     while(app.GetEvent(event)) 
     { 
      if (event.Type == sf::Event::Closed) 
       app.Close(); 
      if ((event.Type == sf::Event::KeyPressed) && (event.Key.Code == sf::Key::Escape)) 
       app.Close(); 
      if (m_downKeyPressed) 
       std::cout << "down key pressed!"; 
      else if(m_leftKeyPressed) 
       std::cout << "left key pressed!"; 
      else if(m_upKeyPressed) 
       std::cout << "up key pressed!"; 
      else if(m_rightKeyPressed) 
       std::cout << "right key pressed!"; 
     } 
    } 

} 

WindowInitializer::~WindowInitializer() 
{ 
    delete m_app; 
} 

我的錯誤是:

In file included from /usr/include/SFML/Window.hpp:35:0, 
       from ../SFML_tutorial/window_initializer.cpp:3: 
/usr/include/SFML/System/NonCopyable.hpp: In copy constructor ‘sf::Input::Input(const sf::Input&)’: 
/usr/include/SFML/System/NonCopyable.hpp:57:5: error: ‘sf::NonCopyable::NonCopyable(const sf::NonCopyable&)’ is private 
/usr/include/SFML/Window/Input.hpp:45:1: error: within this context 
../SFML_tutorial/window_initializer.cpp: In member function ‘void WindowInitializer::initialize_booleans(const sf::Window*)’: 
../SFML_tutorial/window_initializer.cpp:9:37: note: synthesized method ‘sf::Input::Input(const sf::Input&)’ first required here 
../SFML_tutorial/window_initializer.cpp: In destructor ‘WindowInitializer::~WindowInitializer()’: 
../SFML_tutorial/window_initializer.cpp:51:12: error: ‘m_app’ was not declared in this scope 
+0

我會在一會兒發佈它們...... – zeboidlund

+0

下一次,請發佈*最小*示例。也就是說,將錯誤減少到發生的地方。這也將幫助你自己瞭解錯誤。不要在標題中使用「HELP」這樣的詞 - 這沒有幫助。 –

回答

3

錯誤消息應該清楚:

  1. 無法複製sf::Input。您需要使用參考。

    sf::Input& input = app->GetInput(); 
    
  2. 你的析構函數刪除對象不存在。該變量從未被聲明。

相關問題