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