![](/img/trans.png)
[英]“error C2248: 'sf::NonCopyable::NonCopyable' : cannot access private member declared in class 'sf::NonCopyable'”
[英]error C2248: 'sf::NonCopyable::NonCopyable'
我想在SFML库中创建简单的形状,但无法弄清楚如何在多个文件中共享项目。 我知道外观如何,但是我想知道为什么这不起作用
主文件:
#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();
}
}
和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);
}
};
我必须创建此球列表,我是C ++的新手,我仅使用Java创建项目,但首先我想知道如何共享此项目
您通过值传递sf::RenderWindow
,因此它尝试创建一个副本,但是sf::RenderWindow
类是不可复制的,如错误消息所示。
通过引用传递它,或者更好地从sf::Drawable
派生您的Ball
类,并实现draw()
函数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.