Damian Pasierowski Damian Pasierowski - 1 month ago 6
C++ Question

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

Answer

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.

Comments