首页 > 解决方案 > SFML:矢量 2无法编译

问题描述

我有无法编译的代码。如果我sf::Vector2<double>sf::Vector2f. 我试过typedef了,但没有任何区别。

#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;
}

第一个错误:

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

标签: c++templatessfml

解决方案


sf::Vertex构造函数不接受双向量,只接受浮点向量。请参阅文档


推荐阅读