来自sfml示例的refacored pong中的棘手错误

时间:2015-01-31 14:43:35

标签: c++ qt-creator sfml pong

我正在通过pong示例学习SFML。

可以找到原始代码there。我试图将这些行放在一个函数中,然后拨打电话:

    sf::RenderWindow window(
        sf::VideoMode( gameWidth, gameHeight, 32 ),
        "SFML Pong",
        sf::Style::Titlebar | sf::Style::Close
    );
    window.setVerticalSyncEnabled( true );

sf::RenderWindow
CreateWindow( int width, int height, int color_depth, std::string title ){
    sf::RenderWindow window( sf::VideoMode( width, height, color_depth ), title );
    window.setVerticalSyncEnabled( true );
    return window;
}
//....
sf::RenderWindow window = CreateWindow( gameWidth, gameHeight, 32, "My SFML pong" );

获得一大堆非显而易见的errors。我做错了什么?

1 个答案:

答案 0 :(得分:1)

第一个错误告诉您需要知道的一切:

In file included from /usr/include/SFML/System/Lock.hpp:32:0,
             from /usr/include/SFML/System.hpp:36,
             from /usr/include/SFML/Window.hpp:32,
             from /usr/include/SFML/Graphics.hpp:32,
             from main.cpp:5:
/usr/include/SFML/System/NonCopyable.hpp: In copy constructor ‘sf::Window::Window(const sf::Window&)’:
/usr/include/SFML/System/NonCopyable.hpp:67:5: error: ‘sf::NonCopyable::NonCopyable(const sf::NonCopyable&)’ is private NonCopyable(const NonCopyable&);

Window是继承NonCopyable。因此,您无法从函数返回它。

解决方案包括将窗口引用作为函数的输入:

void CreateWindow( sf::RenderWindow& window, int width, int height, int color_depth, std::string title )