当尝试创建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<unsigned int>
成功地创建窗口,但是从SFML教程中可以看出,这似乎没有必要。
这只是新的方式吗?还是我漏掉了什么?
发布于 2022-05-29 19:50:21
这只是新的方式吗?
是的,他们做了一些改变。
下面是源文件中的更改:
这是:
VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32);
现在是这样:
explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32);
看看它吧,这里。
https://stackoverflow.com/questions/72426626
复制相似问题