【发布时间】:2020-11-04 10:42:39
【问题描述】:
我有以下 Graph 类:
class Graph {
private:
struct Edge {
string vertex1{}, vertex2{};
int val{};
Edge() = default;
~Edge() = default;
explicit Edge(string v1, string v2, int value) : vertex1(std::move(v1)), vertex2(std::move(v2)), val(value) {};
bool operator==(const Edge&) const;
};
unordered_map<Edge, Edge*> edges;
public:
Graph() = default;
~Graph();
}
当我想用默认构造函数构造一个 Graph 时,它会显示Explicitly defaulted default constructor of 'Graph' is implicitly deleted because field 'edges' has a deleted default constructor。我应该如何更改我的代码,以便能够使用 Graph 的默认构造函数?
【问题讨论】:
标签: c++ unordered-map default-constructor