SFML - 尝试将窗口重载为函数参数

问题描述 投票:0回答:1

我在 Visual Studio 2019 中使用 SFML 和 C++。我想尝试创建一个函数来简化将文本打印到窗口的过程。

#include "SFML/Graphics.hpp"
#include "SFML/Window.hpp"
#include <string>

void type_text(std::string t, sf::RenderWindow w) {
        sf::Font font;

        font.loadFromFile("consola.ttf");

        sf::Text text(t, font, 12);
        w.draw(text);
        w.display();
}

int main() {
    sf::RenderWindow window(sf::VideoMode(860, 540), "Test");
    sf::Event e;

    while (window.isOpen()) {
        while (window.pollEvent(e)) {
            if (e.type == sf::Event::Closed)
                window.close();
        }
    }
    
    type_text("this is a test", window); // <= THE PROBLEM

    return 0;
}

在问题行上,“窗口”带有下划线作为错误。错误提示

sf::RenderWindow::RenderWindow(const sf::RenderWindow &)': attempting to reference a deleted function

基本上,我该如何制作才能使用 window 来重载该函数并使用它?

c++ class window overloading sfml
1个回答
0
投票

窗口对象

sf::RenderWindow w
无法复制,必须通过引用
sf::RenderWindow &w
传递给
type_text()

© www.soinside.com 2019 - 2024. All rights reserved.