[英]Templated typedef soup using boost graph library
I am trying to create a class that expands on the behavior of the boost graph library. 我正在尝试创建一个扩展增强图谱库行为的类。 I would like my class to be a template, where the user supplies a type (class) which will be used to store properties at every vertex.
我希望我的类成为一个模板,用户在其中提供一个类型(类),该类型将用于存储每个顶点的属性。 That's just background.
那只是背景。 I'm struggling with creating a more succinct typedef to use in defining my new class.
我正在努力创建一个更简洁的typedef来定义我的新类。
Based on other posts like this and this , I decided to define a struct that will contain the templated typedefs. 基于其他职位喜欢这个和这个 ,我决定来定义一个struct将包含模板的typedef。
I'll show two closely related approaches. 我将展示两种密切相关的方法。 I can't figure out why the first typedef for GraphType seems to be working while the second for VertexType fails.
我不知道为什么GraphType的第一个typedef似乎可以工作,而VertexType的第二个typedef却不能工作。
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
template <class VP>
struct GraphTypes
{
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP > GraphType;
typedef boost::graph_traits< GraphType >::vertex_descriptor VertexType;
};
int main()
{
GraphTypes<int>::GraphType aGraphInstance;
GraphTypes<int>::VertexType aVertexInstance;
return 0;
}
Compiler output: 编译器输出:
$ g++ -I/Developer/boost graph_typedef.cpp
graph_typedef.cpp:8: error: type ‘boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP, boost::no_property, boost::no_property, boost::listS> >’ is not derived from type ‘GraphTypes<VP>’
graph_typedef.cpp:8: error: expected ‘;’ before ‘VertexType’
graph_typedef.cpp: In function ‘int main()’:
graph_typedef.cpp:14: error: ‘VertexType’ is not a member of ‘GraphTypes<int>’
graph_typedef.cpp:14: error: expected `;' before ‘aVertexInstance’
Same thing, just avoiding use of GraphType
in the second typedef: 同样,只是避免在第二个typedef中使用
GraphType
:
#include <boost/graph/graph_traits.hpp>
#include <boost/graph/adjacency_list.hpp>
template <class VP>
struct GraphTypes
{
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP > GraphType;
typedef boost::graph_traits< boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP > >::vertex_descriptor VertexType;
};
int main()
{
GraphTypes<int>::GraphType aGraphInstance;
GraphTypes<int>::VertexType aVertexInstance;
return 0;
}
Compiler output looks effectively the same: 编译器输出看起来实际上是相同的:
g++ -I/Developer/boost graph_typedef.cpp
graph_typedef.cpp:8: error: type ‘boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP, boost::no_property, boost::no_property, boost::listS> >’ is not derived from type ‘GraphTypes<VP>’
graph_typedef.cpp:8: error: expected ‘;’ before ‘VertexType’
graph_typedef.cpp: In function ‘int main()’:
graph_typedef.cpp:14: error: ‘VertexType’ is not a member of ‘GraphTypes<int>’
graph_typedef.cpp:14: error: expected `;' before ‘aVertexInstance’
Obviously the first compiler error is the root problem. 显然,第一个编译器错误是根本问题。 I tried inserting
typename
in a few places with no success. 我尝试在一些地方插入
typename
,但没有成功。 I'm using gcc 4.2.1 我正在使用gcc 4.2.1
How do I fix this? 我该如何解决?
typedef typename boost::graph_traits<GraphType>::vertex_descriptor VertexType;
// ^^^^^^^^
Should fix it, I don't know where you tried to put it though.. you might have other problems I don't see. 应该修复它,但我不知道您尝试将其放置在哪里..您可能还有其他我看不到的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.