我正在尝试使用捆绑属性设置顶点的Boost Graph。不幸的是," add_edge"步骤似乎不起作用导致以下错误。任何见解都会有所帮助!
error: constructor for 'boost::detail::adj_list_gen<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node,boost::no_property, boost::no_property, boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property, boost::no_property, boost::listS>::config::rand_stored_vertex'
must explicitly initialize the member 'm_property' which does not have a default constructor
rand_stored_vertex() { }
以及其他一系列此类声明的最终结果如下:
in instantiation of function template specialization 'boost::add_edge<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property,boost::no_property, boost::listS>, boost::detail::adj_list_gen<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property, boost::no_property,boost::listS>, boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property, boost::no_property, boost::listS>::config,boost::undirected_graph_helper<boost::detail::adj_list_gen<boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property, boost::no_property, boost::listS>,boost::vecS, boost::vecS, boost::undirectedS, Node, boost::no_property, boost::no_property, boost::listS>::config> >' requested here
boost::add_edge( svlist[0], svlist[1], SG );
class Node {
public:
std::string id;
Node(int a) {
id = std::to_string(a);
}
};
std::vector<Node> nodelist;
Node n1(1);
Node n2(2);
Node n3(3);
Node n4(4);
nodelist.push_back(n1);
nodelist.push_back(n2);
nodelist.push_back(n2);
nodelist.push_back(n4);
typedef boost::adjacency_list< boost::vecS, boost::vecS,
boost::undirectedS, Node> ScafGraph;
typedef boost::graph_traits<ScafGraph>::vertex_descriptor SV;
typedef boost::graph_traits<ScafGraph>::edge_descriptor SE;
ScafGraph SG;
std::vector<SV> svlist;
for(int i=0; i<4; i++) {
SV v = boost::add_vertex( nodelist[i], SG );
svlist.push_back(v);
}
SE e; bool ok;
boost::tie(e, ok) = boost::edge( svlist[0], svlist[1], SG );
if(!ok) {
boost::add_edge( svlist[0], svlist[1], SG );
}
答案 0 :(得分:1)
Node
课程中有一些错误。在Windows中使用C ++ 11在GCC 4.9.0中进行了测试。
class Node {
public:
std::string id;
Node(int a) { id = std::to_string(a); }
Node() = default;
};
Node
后的括号错误。int
并转换为字符串的构造函数,转换参数was not used
。vertex
时向图表添加edge
或vecS
要求所使用的节点具有默认构造函数,因为该向量可能需要增长并重新分配元素,当它成长时,元素是默认构造的。如果是自定义节点,则没有默认构造函数。