gpt4 book ai didi

c++ - 来自 sfml 示例的重构 pong 中的棘手错误

转载 作者:行者123 更新时间:2023-11-28 06:27:34 24 4
gpt4 key购买 nike

我正在通过乒乓球示例学习 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 .我做错了什么?

最佳答案

第一个错误告诉你所有你需要知道的:

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 )

关于c++ - 来自 sfml 示例的重构 pong 中的棘手错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28252842/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com