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

"Attempting to Reference a deleted function" error when attempting to initialize static RenderWindor

Error:

enter image description here

…is on line 15, where I try to initialize window:

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

#include <iostream>

#include <SFML/Graphics.hpp>

static class Renderer {

public:
    static sf::RenderWindow window;
    
      
};
sf::RenderWindow Renderer::window = sf::RenderWindow(sf::VideoMode(1200, 1000), "Proj");
class Quad {
public:
    sf::Vector2<float> Scale;
    sf::Vector2<float> Pos;
public:
    Quad(sf::Vector2<float> P, sf::Vector2<float> S) {
        Pos = P;
        Scale = S;
    }
    sf::RectangleShape RenderMe() {
        sf::RectangleShape s;
        s.setScale(Scale);
        s.setPosition(Pos);
        return s;
    }
};

int main()
{
    std::cout << "Hello World!\n";
    
        new Renderer;

       
       
           Quad s(sf::Vector2<float>(40,40), sf::Vector2<float>(20,20));
           


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

            Renderer::window.clear();
            Renderer::window.draw(s.RenderMe());
            Renderer::window.display();
        }

        return 0;
    
    return 0;
    
}

Everything else in the script works.

As far as I can tell, I have set up my filesystems correctly, and all issues are with my script (I think)

I have mostly tried moving around the init, as well as changing certain bits, like not including all of it, but those all caused different errors and this seemed the most correct.

>Solution :

Remove everything to do with class Renderer and Renderer::window.
Put a single definition at the top of your main function:

sf::RenderWindow window(sf::VideoMode(1200, 1000), "Proj");

and use window wherever you used Renderer::window.

If you insist on having a Renderer object, it should look like this:

class Renderer {
  public:
    sf::RenderWindow window;
    Renderer() : window(sf::VideoMode(1200, 1000), "Proj")) {}
};

and a simple Renderer r; in your main function will suffice.

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