Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Trouble creating an SFML Window

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:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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?

>Solution :

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.

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading