【问题标题】:SMFL "Cannot be Referenced, it is a deleted function"SMFL“不能被引用,它是一个被删除的函数”
【发布时间】:2016-05-05 10:55:13
【问题描述】:

我的 DrawCircles(window) 有问题;方法。

当我尝试传入“窗口”时,我的标题中出现错误。

知道如何解决这个问题吗?此外,将不胜感激,谢谢。

这是我的代码:

#include <SFML/Graphics.hpp>
#include <vector>
using namespace std;


vector<sf::CircleShape> Shapes;


int main() {

    sf::RenderWindow window(sf::VideoMode(1280, 720), "Conduit");




    while (window.isOpen()) {

        sf::Event event;
        while (window.pollEvent(event)) {

            if (event.type == sf::Event::Closed)
                window.close();
        }

        window.clear();
        DrawCircles(window);            // ERROR IS THIS LINE.
        //window.draw(shape);  
        window.display();
    }

}


void RenderCircle()
{
    sf::CircleShape shape;
    shape.setRadius(40.f);
    shape.setPosition(100.f, 100.f);
    shape.setFillColor(sf::Color::Cyan);

    Shapes.push_back(shape);
}

void DrawCircles(sf::RenderWindow window)
{

    for (int i = 0; i < Shapes.size(); i++)
    {
        window.draw(Shapes.at(i));
    }
}

【问题讨论】:

  • 我该怎么做?

标签: c++ sfml


【解决方案1】:

请尝试在代码顶部添加 DrawCircles 方法的原型。并添加所有其他方法的原型。试试这个:

 #include <SFML/Graphics.hpp>
    #include <vector>
    using namespace std;


    void DrawCircles(sf::RenderWindow &window);
    vector<sf::CircleShape> Shapes;
    .. rest of code

void DrawCircles(sf::RenderWindow &window)
{

    for (int i = 0; i < Shapes.size(); i++)
    {
        window.draw(Shapes.at(i));
    }
}

【讨论】:

  • 好吧,除了 void RenderCircle() 本身之外,这实际上就是所有这些。
  • 谢谢,这行得通,有什么解释为什么行得通吗?和指针有关吗?
  • 很高兴它成功了。这完全是关于复制 sf::RenderWindow。如果您不使用 & (表示引用) - 您正在尝试复制您的 sf::RenderWindow。但是 sf::RenderWindow 不能被复制(要复制对象,类使用复制构造函数,而 sf::RenderWindow 没有)。如果您在此处使用引用,则不是在复制或尝试复制任何内容,您只是在使用与您在主函数中声明的完全相同的 sf::RenderWindow。希望对您有所帮助。
猜你喜欢
  • 2014-05-09
  • 2020-08-09
  • 2022-11-12
  • 2018-06-09
  • 1970-01-01
  • 1970-01-01
  • 2011-11-05
  • 2010-12-12
  • 1970-01-01
相关资源
最近更新 更多