难以创建SFML窗口

发布于 2025-02-02 15:57:12 字数 1781 浏览 3 评论 0原文

尝试创建SFML窗口时,sf :: Videomode(800,600)给出了构造函数不可行的错误。

源代码:

#include <SFML/Window.hpp>

int main() {
    sf::Window window(sf::VideoMode(800, 600), "Pong");

    return 0;
}

错误日志:

Consolidate compiler generated dependencies of target pong-cpp
[ 50%] Building CXX object CMakeFiles/pong-cpp.dir/src/main.cpp.o
/Users/larrymason/Desktop/repos/pong-cpp/src/main.cpp:4:23: error: no matching constructor for initialization of 'sf::VideoMode'
    sf::Window window(sf::VideoMode(800, 600), "Pong");
                      ^             ~~~~~~~~
/usr/local/include/SFML/Window/VideoMode.hpp:61:14: note: candidate constructor not viable: no known conversion from 'int' to 'const sf::Vector2u' (aka 'const Vector2<unsigned int>') for 1st argument
    explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);
             ^
/usr/local/include/SFML/Window/VideoMode.hpp:42:23: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class SFML_WINDOW_API VideoMode
                      ^
/usr/local/include/SFML/Window/VideoMode.hpp:42:23: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
/usr/local/include/SFML/Window/VideoMode.hpp:52:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
    VideoMode();
    ^
1 error generated.
make[2]: *** [CMakeFiles/pong-cpp.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/pong-cpp.dir/all] Error 2
make: *** [all] Error 2

对我的理解以及从我阅读/观看的教程中,这是创建窗口的标准方法。我可以使用sf :: vector2&lt; unsigned int&gt;成功创建窗口,但是从查看SFML教程来看,这似乎不是必需的。

这只是新方法吗?还是我想念什么?

When trying to create an SFML window, sf::VideoMode(800, 600) gives a constructor not viable error.

Source code:

#include <SFML/Window.hpp>

int main() {
    sf::Window window(sf::VideoMode(800, 600), "Pong");

    return 0;
}

Error log:

Consolidate compiler generated dependencies of target pong-cpp
[ 50%] Building CXX object CMakeFiles/pong-cpp.dir/src/main.cpp.o
/Users/larrymason/Desktop/repos/pong-cpp/src/main.cpp:4:23: error: no matching constructor for initialization of 'sf::VideoMode'
    sf::Window window(sf::VideoMode(800, 600), "Pong");
                      ^             ~~~~~~~~
/usr/local/include/SFML/Window/VideoMode.hpp:61:14: note: candidate constructor not viable: no known conversion from 'int' to 'const sf::Vector2u' (aka 'const Vector2<unsigned int>') for 1st argument
    explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);
             ^
/usr/local/include/SFML/Window/VideoMode.hpp:42:23: note: candidate constructor (the implicit copy constructor) not viable: requires 1 argument, but 2 were provided
class SFML_WINDOW_API VideoMode
                      ^
/usr/local/include/SFML/Window/VideoMode.hpp:42:23: note: candidate constructor (the implicit move constructor) not viable: requires 1 argument, but 2 were provided
/usr/local/include/SFML/Window/VideoMode.hpp:52:5: note: candidate constructor not viable: requires 0 arguments, but 2 were provided
    VideoMode();
    ^
1 error generated.
make[2]: *** [CMakeFiles/pong-cpp.dir/src/main.cpp.o] Error 1
make[1]: *** [CMakeFiles/pong-cpp.dir/all] Error 2
make: *** [all] Error 2

To my understanding and from the tutorials I've read/watched, this is the standard way of creating a window. I can successfully create the window using a sf::Vector2<unsigned int> however from looking at the SFML tutorials, this doesn't appear to be necessary.

Is this just the new way? Or am I missing something?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

深白境迁sunset 2025-02-09 15:57:12

这只是新方法吗?

是的,他们进行了一些更改。

这是源文件的更改:

VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32);

是:现在:

explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);

看看78769A8FD1001820CF2040BR61“ rel =“ nofollow noreferrer”>在这里。

Is this just the new way?

Yes, they have made some changes.

Here are the changes from the source file:
This:

VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32);

is now this:

explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);

Take a look at it here.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文