Search code examples
c++templatessfml

SFML: Vector2<double> can't compile


I have this code that I can't compile. It works fine if I replace sf::Vector2<double> with sf::Vector2f. I've tried typedef, but it didn't make any difference.

#include <SFML/Graphics.hpp>

int main() {
    sf::RenderWindow window(sf::VideoMode(200, 200), "SFML works!");

    sf::Vertex line[] =
    {       
        sf::Vertex(sf::Vector2<double>(10.0, 10.0)),
        sf::Vertex(sf::Vector2<double>(150.0, 150.0))
    };

    while (window.isOpen())
    {
        sf::Event event;
        while (window.pollEvent(event))
        {
            if (event.type == sf::Event::Closed)
            {
                window.close();
            }
        }

        window.clear();
        window.draw(line, 2, sf::Lines);
        window.display();
    }

    return 0;
}

The first error:

test.cpp: In function ‘int main()’:
test.cpp:9:47: error: no matching function for call to ‘sf::Vertex::Vertex(sf::Vector2<double>)’

Solution

  • sf::Vertex constructor does not take double vectors, only float vectors. See the documentation.