- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
给定以下代码
测试.h:
#ifndef __graph_aufbau_header__
#define __graph_aufbau_header__
#include <vector>
#include <queue>
#include <string>
using namespace std;
class Knoten {
public:
unsigned int nummer;
double x_1;
double x_2;
unsigned int abstand;
Knoten(unsigned int num, double x1, double x2) : nummer(num), x_1(x1), x_2(x2), abstand(-1) {};
Knoten(Knoten&& anderer) : nummer(anderer.nummer), x_1(anderer.x_1), x_2(anderer.x_2), abstand(anderer.abstand) {};
Knoten& operator=(Knoten&& anderer) = default;
};
class Kante {
public:
unsigned int quellknotennum;
unsigned int zielknotennum;
unsigned int gewicht;
Kante(unsigned int qnum, unsigned int znum, unsigned int gew)
: quellknotennum(qnum), zielknotennum(znum), gewicht(gew)
{};
Kante(Kante&& andere)
: quellknotennum(andere.quellknotennum),
zielknotennum(andere.zielknotennum),
gewicht(andere.gewicht) {};
Kante& operator=(const Kante& andere) = default;
inline bool operator<(const Kante& kante_2){
return this->quellknotennum < kante_2.quellknotennum;
};
};
class Offset {
public:
unsigned int knoten_num;
unsigned int kanten_num;
Offset(unsigned int knnum, unsigned int kanum)
: knoten_num(knnum), kanten_num(kanum)
{};
Offset(Offset&& anderer)
: knoten_num(anderer.knoten_num), kanten_num(anderer.kanten_num) {};
Offset& operator=(Offset& anderer) = default;
};
class Graph {
public:
vector<Knoten> coordList;
vector<Kante> edgeList;
vector<Offset> edgeOffsets;
//vector<unsigned int> abstand;
Graph() : coordList(), edgeList(), edgeOffsets(){};
void knoten_einlesen(double x_1, double x_2);
void kante_einlesen(unsigned int quellknoten, unsigned int zielknoten, unsigned int gewicht);
void offset_einlesen(unsigned int nummer, unsigned int kante);
void einlesen(string quelle);
Knoten naechster_Nachbar(Knoten& knoten);
};
#endif
测试.cc:
// kein iostream
#include <fstream> // benötigt für die Deklaration eines Dateistroms
#include <iostream>
#include <string>
#include <sstream> // zum Splitten
//#include <regex>
#include <cstdlib> // Zur Umwandlung von Strings in Doubles
#include <algorithm> // fuer find_if()
#include <queue>
#include <vector>
#include "test.h"
using namespace std;
void Graph::knoten_einlesen(double x_1, double x_2){
unsigned int neue_position = coordList.size();
coordList.emplace_back(neue_position, x_1, x_2);
}
void Graph::kante_einlesen(unsigned int knoten_1, unsigned int knoten_2, unsigned int gewicht){
edgeList.emplace_back(knoten_1, knoten_2, gewicht);
}
void Graph::offset_einlesen(unsigned int nummer, unsigned int kante){
edgeOffsets.emplace_back(nummer, kante);
}
void Graph::einlesen(string quelle){
ifstream datendatei(quelle);
if (datendatei.is_open()){
string aktuelle_zeile;
getline(datendatei, aktuelle_zeile);
unsigned int anzahl_knoten = stoi(aktuelle_zeile);
getline(datendatei, aktuelle_zeile);
unsigned int anzahl_kanten = stoi(aktuelle_zeile);
unsigned int nummer, position;
for(auto& knoten: coordList){
nummer = knoten.nummer;
auto erste_kante = find_if(edgeList.begin(), edgeList.end(), [nummer] (Kante kante)\
{return nummer == kante.quellknotennum;});
position = erste_kante - edgeList.begin(); // Position der ersten Kante, die mit dem Knoten verbunden ist, in edgeOffsets
offset_einlesen(nummer, position);
}
datendatei.close();
}
}
Knoten Graph::naechster_Nachbar(Knoten& knoten){
return coordList.at(edgeList.at(edgeOffsets.at(knoten.nummer).kanten_num).zielknotennum);
}
,我通过调用 g++ -std=gnu++11 test.cc
收到以下错误:
test.cc: In member function 'Knoten Graph::naechster_Nachbar(Knoten&)':
test.cc:55:96: error: use of deleted function 'constexpr Knoten::Knoten(const Knoten&)'
return coordList.at(edgeList.at(edgeOffsets.at(knoten.nummer).kanten_num).zielknotennum);
^
In file included from test.cc:11:0:
test.h:10:11: note: 'constexpr Knoten::Knoten(const Knoten&)' is implicitly declared as deleted because 'Knoten' declares a move constructor or move assignment operator
class Knoten {
^~~~~~
In file included from C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/stl_algobase.h:71:0,
from C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/char_traits.h:39,
from C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/ios:40,
from C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/istream:38,
from C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/fstream:38,
from test.cc:2:
C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/predefined_ops.h: In instantiation of 'bool __gnu_cxx::__ops::_Iter_pred<_Predicate>::operator()(_Iterator) [with _Iterator = __gnu_cxx::__normal_iterator<Kante*, std::vector<Kante> >; _Predicate = Graph::einlesen(std::__cxx11::string)::<lambda(Kante)>]':
C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/stl_algo.h:120:14: required from '_RandomAccessIterator std::__find_if(_RandomAccessIterator, _RandomAccessIterator, _Predicate, std::random_access_iterator_tag) [with _RandomAccessIterator = __gnu_cxx::__normal_iterator<Kante*, std::vector<Kante> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<Graph::einlesen(std::__cxx11::string)::<lambda(Kante)> >]'
C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/stl_algo.h:161:23: required from '_Iterator std::__find_if(_Iterator, _Iterator, _Predicate) [with _Iterator = __gnu_cxx::__normal_iterator<Kante*, std::vector<Kante> >; _Predicate = __gnu_cxx::__ops::_Iter_pred<Graph::einlesen(std::__cxx11::string)::<lambda(Kante)> >]'
C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/stl_algo.h:3817:28: required from '_IIter std::find_if(_IIter, _IIter, _Predicate) [with _IIter = __gnu_cxx::__normal_iterator<Kante*, std::vector<Kante> >; _Predicate = Graph::einlesen(std::__cxx11::string)::<lambda(Kante)>]'
test.cc:44:57: required from here
C:/Program Files/mingw-w64/x86_64-6.2.0-win32-seh-rt_v5-rev1/mingw64/lib/gcc/x86_64-w64-mingw32/6.2.0/include/c++/bits/predefined_ops.h:234:11: error: use of deleted function 'constexpr Kante::Kante(const Kante&)'
{ return bool(_M_pred(*__it)); }
^~~~~~~~~~~~~~~~~~~~
In file included from test.cc:11:0:
test.h:22:11: note: 'constexpr Kante::Kante(const Kante&)' is implicitly declared as deleted because 'Kante' declares a move constructor or move assignment operator
class Kante {
^~~~~
test.cc:43:99: note: initializing argument 1 of 'Graph::einlesen(std::__cxx11::string)::<lambda(Kante)>'
auto erste_kante = find_if(edgeList.begin(), edgeList.end(), [nummer] (Kante kante)\
^
(不要错过打印在右侧隐藏面的错误)
我已经尝试了很多小时来解决这个问题,今天,我不知道这里出了什么问题。显然,代码在方法 naechster_nachbar(..) 中调用了类“Knoten”的隐式删除移动构造函数 - 但我不知道为什么会发生这种情况以及如何防止相应的错误消息。
另一部分(大的,有点模糊的部分)可能是在函数 einlesen(...)(lambda 函数?)的某处引起的,原因可能与第一个相同。
给定的代码不需要能够独立编译,甚至不需要完整和有意义;它的唯一目标是演示生成的错误消息。我无法进一步缩小这个最小示例的大小。我们被迫使用 C++ 11(因此命令行选项是必需的)。
非常感谢!
最佳答案
Knoten Graph::naechster_Nachbar(Knoten&)
按值返回,因此尝试复制 Knoten
。但它不能,因为该类只有移动构造函数而没有复制构造函数。
有趣的是,移动构造函数实际上复制了 anderer
中的所有数据,因此它可能只是一个复制构造函数。
关于c++ - emplace_back 和移动赋值构造函数的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41684936/
关闭。这个问题是off-topic .它目前不接受答案。 想要改进这个问题? Update the question所以它是on-topic用于堆栈溢出。 关闭 12 年前。 Improve thi
我有一个动态网格,其中的数据功能需要正常工作,这样我才能逐步复制网格中的数据。假设在第 5 行中,我输入 10,则从第 6 行开始的后续行应从 11 开始读取,依此类推。 如果我转到空白的第一行并输入
我有一个关于我的按钮消失的问题 我已经把一个图像作为我的按钮 用这个函数动画 function example_animate(px) { $('#cont
我有一个具有 Facebook 连接和经典用户名/密码登录的网站。目前,如果用户单击 facebook_connect 按钮,系统即可运行。但是,我想将现有帐户链接到 facebook,因为用户可以选
我有一个正在为 iOS 开发的应用程序,该应用程序执行以下操作 加载和设置注释并启动核心定位和缩放到位置。 map 上有很多注释,从数据加载不会花很长时间,但将它们实际渲染到 map 上需要一段时间。
我被推荐使用 Heroku for Ruby on Rails 托管,到目前为止,我认为我真的会喜欢它。只是想知道是否有人可以帮助我找出问题所在。 我按照那里的说明在该网站上创建应用程序,创建并提交
我看过很多关于 SSL 错误的帖子和信息,我自己也偶然发现了一个。 我正在尝试使用 GlobalSign CA BE 证书通过 Android WebView 访问网页,但出现了不可信错误。 对于大多
我想开始使用 OpenGL 3+ 和 4,但我在使用 Glew 时遇到了问题。我试图将 glew32.lib 包含在附加依赖项中,并且我已将库和 .dll 移动到主文件夹中,因此不应该有任何路径问题。
我已经盯着这两个下载页面的源代码看了一段时间,但我似乎找不到问题。 我有两个下载页面,一个 javascript 可以工作,一个没有。 工作:http://justupload.it/v/lfd7不是
我一直在使用 jQuery,只是尝试在单击链接时替换文本字段以及隐藏/显示内容项。它似乎在 IE 中工作得很好,但我似乎无法让它在 FF 中工作。 我的 jQuery: $(function() {
我正在尝试为 NDK 编译套接字库,但出现以下两个错误: error: 'close' was not declared in this scope 和 error: 'min' is not a m
我正在使用 Selenium 浏览器自动化框架测试网站。在测试过程中,我切换到特定的框架,我们将其称为“frame_1”。后来,我在 Select 类中使用了 deselectAll() 方法。不久之
我正在尝试通过 Python 创建到 Heroku PostgreSQL 数据库的连接。我将 Windows10 与 Python 3.6.8 和 PostgreSQL 9.6 一起使用。 我从“ht
我有一个包含 2 列的数据框,我想根据两列之间的比较创建第三列。 所以逻辑是:第 1 列 val = 3,第 2 列 val = 4,因此新列值什么都没有 第 1 列 val = 3,第 2 列 va
我想知道如何调试 iphone 5 中的 css 问题。 我尝试使用 firelite 插件。但是从纵向旋转到横向时,火石占据了整个屏幕。 有没有其他方法可以调试 iphone 5 中的 css 问题
所以我有点难以理解为什么这不起作用。我正在尝试替换我正在处理的示例站点上的类别复选框。我试图让它做以下事情:未选中时以一种方式出现,悬停时以另一种方式出现(选中或未选中)选中时以第三种方式出现(而不是
Javascript CSS 问题: 我正在使用一个文本框来写入一个 div。我使用以下 javascript 获取文本框来执行此操作: function process_input(){
你好,我很难理解 P、NP 和多项式时间缩减的主题。我试过在网上搜索它并问过我的一些 friend ,但我没有得到任何好的答案。 我想问一个关于这个话题的一般性问题: 设 A,B 为 P 中的语言(或
你好,我一直在研究 https://leetcode.com/problems/2-keys-keyboard/并想到了这个动态规划问题。 您从空白页上的“A”开始,完成后得到一个数字 n,页面上应该
我正在使用 Cocoapods 和 KIF 在 Xcode 服务器上运行持续集成。我已经成功地为一个项目设置了它来报告每次提交。我现在正在使用第二个项目并收到错误: Bot Issue: warnin
我是一名优秀的程序员,十分优秀!