Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/124.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 编译器错误‘;不可复制:不可复制(const NonCopyable&;)&x2019;是私人的_C++_Sfml - Fatal编程技术网

C++ 编译器错误‘;不可复制:不可复制(const NonCopyable&;)&x2019;是私人的

C++ 编译器错误‘;不可复制:不可复制(const NonCopyable&;)&x2019;是私人的,c++,sfml,C++,Sfml,我的代码无法编译。我做错了什么?我还希望sf::Window和sf::Input对象是静态字段。最好的办法是什么 #include <SFML/Window.hpp> #include <SFML/Window/Event.hpp> #ifndef WINDOW_INITIALIZER_H #define WINDOW_INITIALIZER_H class WindowInitializer { public: WindowInitializer();

我的代码无法编译。我做错了什么?我还希望
sf::Window
sf::Input
对象是静态字段。最好的办法是什么

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

错误消息应该是清楚的:

  • 无法复制
    sf::Input
    。你需要使用参考资料

      sf::Input& input = app->GetInput();
    
  • 析构函数正在删除不存在的对象。变量从未声明过


  • 错误消息应该是清楚的:

  • 无法复制
    sf::Input
    。你需要使用参考资料

      sf::Input& input = app->GetInput();
    
  • 析构函数正在删除不存在的对象。变量从未声明过


  • 我马上就发布……下次,请发布一个简单的例子。也就是说,将错误减少到发生错误的地方。这也将帮助您自己理解错误。不要在标题中使用像“帮助”这样的词,那是没有帮助的。我稍后会发布它们……下次,请发布一个简单的例子。也就是说,将错误减少到发生错误的地方。这也将帮助您自己理解错误。不要在标题中使用像“帮助”这样的词——那没有帮助。