- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
当我尝试编译以下代码时:
SFMLSet.cpp:
#include "SFMLSet.h"
SFMLSet::SFMLSet(string texturePath)
{
if(!texture.loadFromFile(texturePath)) {
exit(1);
}
new (&app) sf::RenderWindow(sf::VideoMode(texture.getSize().x, texture.getSize().y), texturePath, sf::Style::None);
new (&sprite) sf::Sprite(texture);
}
SFMLSet.h:
#ifndef SFMLSET_H
#define SFMLSET_H
#include <SFML/Graphics.hpp>
#include <string>
#include <cmath>
using namespace std;
class SFMLSet {
public:
sf::RenderWindow app;
sf::Texture texture;
sf::Sprite sprite;
sf::Vector2i grabbedOffset;
bool grabbedWindow = false;
SFMLSet (string texturePath);
sf::Event event;
};
#endif // SFMLSET_H
主要.cpp:
#include <windows.h>
#include <vector>
#include <iostream>
#include "SFMLSet.h"
int main()
{
bool isRunning=true;
vector<SFMLSet> IMGS;
IMGS.push_back (SFMLSet ("cb.bmp"));
while (isRunning)
{
for (int i=0;i<IMGS.size();i++) {
while (IMGS[i].app.pollEvent(IMGS[i].event))
{
if (IMGS[i].event.type == sf::Event::Closed) {
IMGS[i].app.close();
isRunning=false;
}
if (IMGS[i].event.type == sf::Event::KeyPressed && IMGS[i].event.key.code == sf::Keyboard::Escape)
{
IMGS[i].app.close();
isRunning=false;
}
else if (IMGS[i].event.type == sf::Event::MouseButtonPressed)
{
if (IMGS[i].event.mouseButton.button == sf::Mouse::Left)
{
IMGS[i].grabbedOffset = IMGS[i].app.getPosition() - sf::Mouse::getPosition();
IMGS[i].grabbedWindow = true;
}
}
else if (IMGS[i].event.type == sf::Event::MouseButtonReleased)
{
if (IMGS[i].event.mouseButton.button == sf::Mouse::Left)
IMGS[i].grabbedWindow = false;
}
else if (IMGS[i].event.type == sf::Event::MouseMoved)
{
if (IMGS[i].grabbedWindow&&(IMGS[i].grabbedOffset.x<-10&&IMGS[i].grabbedOffset.y<-10)&&(IMGS[i].grabbedOffset.x>-(IMGS[i].texture.getSize().x)+10&&IMGS[i].grabbedOffset.y>-(IMGS[i].texture.getSize().y)+10))
IMGS[i].app.setPosition(sf::Mouse::getPosition() + IMGS[i].grabbedOffset);
}
}
IMGS[i].app.clear();
IMGS[i].app.draw(IMGS[i].sprite);
IMGS[i].app.display();
}
}
return EXIT_SUCCESS;
}
我得到了一些错误:
SFML-2.3.2\include/SFML/System/NonCopyable.hpp:67:5: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
SFML-2.3.2\include/SFML/Window/Window.hpp:57:23: error: within this context
SFML-2.3.2\include/SFML/System/NonCopyable.hpp:67:5: error: 'sf::NonCopyable::NonCopyable(const sf::NonCopyable&)' is private
SFML-2.3.2\include/SFML/Graphics/RenderTarget.hpp:51:25: error: within this context
SFML-2.3.2\include/SFML/System/NonCopyable.hpp:79:18: error: 'sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)' is private
SFML-2.3.2\include/SFML/Window/Window.hpp:57:23: error: within this context
SFML-2.3.2\include/SFML/System/NonCopyable.hpp:79:18: error: 'sf::NonCopyable& sf::NonCopyable::operator=(const sf::NonCopyable&)' is private
SFML-2.3.2\include/SFML/Graphics/RenderTarget.hpp:51:25: error: within this context
如何解决这个问题?
最佳答案
您应该阅读 SFML tutorials ,并像他们的示例一样编写程序。
这里的具体问题是 sf::RenderWindow
的复制构造函数是私有(private)的——通常复制一个窗口是没有意义的。
不幸的是,您在 std::vector
中使用了 SFMLSet
。 vector 必须动态地增加它们的大小,为了实现这一点,它们分配了一个新的更大的缓冲区,并将它们现有的内容复制到新位置——调用 SFMLSet
的复制构造函数,后者又尝试调用sf::RenderWindow
s.
解决此问题的最佳方法可能是从 IMGS 中删除 sf::RenderWindow
,并将其作为局部变量保留在 main
中,同样,就像在教程中一样.您可能不是要为每张图片打开一个新窗口,对吧?
关于C++ SFML 编译错误 sf::NonCopyable::NonCopyable(const sf::NonCopyable&) is private,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38567732/
标记为家庭作业,因为这是我写的期中问题,但我不明白答案。我被要求在以下语句中解释每个 const 的用途: const char const * const GetName() const { ret
const int* const fun(const int* const& p) const; 我试图弄清楚这个给定函数原型(prototype)的输入参数。我在这两个之间争论,不确定哪个是正确的。
下面的代码用于在同时存在 const 和非 const getter 时减少代码重复。它从非 const 创建 const 版本。我搜索了一下,很多人说我应该从 const 创建非 const 版本。
据我所知,TypeScript 查看了 const string变量作为一个不可变的类型变量,只有那个值,没有其他可能的值。一直以为加as const那是多余的。 为什么我在示例的第二部分得到以下内容
我有一个具有以下签名的方法: size_t advanceToNextRuleEntryRelatedIndex( size_t index, size_t nStrings, char const
首先,有什么区别: (1) const char* (2) char const* (3) const char const* 我相当确定我完全理解这一点,但我希望有人能具体地给我一个句子,这样它就会
这里是新手! 我正在阅读一段代码,我看到作者经常写一个成员函数作为 const int func (const scalar& a) const // etc 你看这里有三个const,现在我明白了中
我总是搞乱如何正确使用 const int*、const int * const 和 int const *。是否有一套规则来定义你可以做什么和不能做什么? 我想知道在赋值、传递给函数等方面所有该做和
我见过人们将 const 用作函数参数的代码。使用 const* 与 const * const 有什么好处?这可能是一个非常基本的问题,但如果有人能解释一下,我将不胜感激。 Bool IsThisN
我总是搞乱如何正确使用 const int*、const int * const 和 int const *。是否有一套规则来定义你可以做什么和不能做什么? 我想知道在赋值、传递给函数等方面所有该做和
这个问题在这里已经有了答案: What is the difference between const int*, const int * const, and int const *? (23 个
如果引用的对象不是 const 对象,那么引用“const”关键字的目的是什么? r1 和 r2 的作用(如下)有什么不同吗? int i = 42; // non const object cons
friend 让我解释原因 const const const const const int const i = 0; 是有效的语法。我拒绝对这个话题有任何想法。虽然我很好奇它是否只是语法问题? 编
我总是搞砸如何正确使用 const int*、const int * const 和 int const *。是否有一套规则来定义你能做什么和不能做什么? 我想知道在分配、传递给函数等方面的所有注意事
常量在 const char* push(const char * const &&_data); 表示无法更改引用的内容。为什么我不能将 const char* 传递给 push? 最佳答案 您的代
我有一个关于在函数参数中涉及指针的最佳实践以及它们是否应该指定为 *const 的问题或 const *const .我知道对于 const 的使用或过度使用存在不同的意见。 ,但至少有一些用途是捕捉
我目前正在为我的类(class)写一个作业,它应该充当一个非常基本的外壳。我快完成了,但是我遇到了 execvp 和我的参数字符数组的问题。这是我的代码的一小段。 //Split the left c
所以,我知道了char const *、char * const 和char const * const 之间的区别。那些是: char* the_string : I can change the
我正在运行一些示例程序以重新熟悉 C++,我遇到了以下问题。首先,这里是示例代码: void print_string(const char * the_string) { cout << t
我正在为系统中的编译错误而苦苦挣扎,这是代码 struct Strless : public binary_function { public : bool operator()(cons
我是一名优秀的程序员,十分优秀!