简体   繁体   中英

error C2248: 'sf::NonCopyable::NonCopyable'

I want to create simple shape in SFML library, but I can't figure it out how to share project in multiple files. I known how have to looks like, but I wonder why this not working

main file:

#include <iostream>
#include <SFML/Graphics.hpp>
#include  "Ball.cpp"

using namespace std;
using namespace sf;

int main()
{
    RenderWindow win(VideoMode(800, 800), L"Rozdział 1");

    while (win.isOpen())
    {
        win.clear(Color::White);
        Event e;
        while (win.pollEvent(e))
        {
            if (e.type == Event::Closed)
                win.close();    
        }

        Ball ball(win);
        win.display();
    }
}

and ball.cpp

#include <iostream>
#include <SFML/Graphics.hpp>

using namespace std;
using namespace sf;
class Ball
{

public: Ball(RenderWindow win)
{
    CircleShape circle(50);
    circle.setPosition(0, 0);
    circle.setOutlineColor(Color::Red);
    circle.setOutlineThickness(2);
    Texture texture;
    if (!texture.loadFromFile("textura.png"))
        cerr << "Nie można załadować grafiki\n";

    circle.setTexture(&texture);

    win.draw(circle);
}
};

I must create List of this balls, I am new in the C++, I create projects only in Java, but first I want known how to share this project

You pass the sf::RenderWindow by value thus it tries to crate a copy, but the sf::RenderWindow class is non-copyable, as the error message indicates.

Pass it by reference or better derive your Ball class from sf::Drawable and implement the draw() function.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM