BGL 捆绑属性 add_edge“无匹配函数”
我创建了一个结构体,并将其用作 adjacency_list 的模板参数。但是,当我尝试 add_edge(vertex1, vertex2, property, graph) 时,编译器抱怨“没有匹配的函数调用”。有人能看出我哪里出了问题吗?
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
// Create a struct to hold several properties
struct MyProperty
{
int MyIntProperty;
};
// Define the type of the graph
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, MyProperty> Graph;
int main(int,char*[])
{
// Create a graph object
Graph g(2);
// Add an edge between node 0 and node 1 with weight 1.2
MyProperty p;
p.MyIntProperty = 5;
std::cout << p.MyIntProperty << std::endl;
add_edge(0, 1, p, g);
return 0;
}
谢谢,
大卫
I have created a struct, and used it as a template parameter to adjacency_list. However, when I try to add_edge(vertex1, vertex2, property, graph) , the compiler complains "no matching function call". Can anyone see where I've gone wrong here?
#include <iostream>
#include <boost/graph/adjacency_list.hpp>
// Create a struct to hold several properties
struct MyProperty
{
int MyIntProperty;
};
// Define the type of the graph
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::undirectedS, MyProperty> Graph;
int main(int,char*[])
{
// Create a graph object
Graph g(2);
// Add an edge between node 0 and node 1 with weight 1.2
MyProperty p;
p.MyIntProperty = 5;
std::cout << p.MyIntProperty << std::endl;
add_edge(0, 1, p, g);
return 0;
}
Thanks,
David
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在此代码中,
MyProperty
被声明为顶点属性而不是边属性,因此插入具有该属性的边是没有意义的。尝试在adjacency_list
typedef 中的MyProperty
之前添加boost::no_property
。In this code,
MyProperty
is declared as a vertex property rather than an edge property, and so it doesn't make sense to insert edges with that property. Try addingboost::no_property
beforeMyProperty
in youradjacency_list
typedef.