使用boost图库的模板typedef汤
Templated typedef soup using boost graph library
我正在尝试创建一个扩展boost图库行为的类。我希望我的类是一个模板,用户在其中提供一个类型(类),用于存储每个顶点的属性。这只是背景。我正在努力创建一个更简洁的typedef来定义我的新类。
基于其他类似的文章,我决定定义一个包含模板化typedefs的结构。
我将展示两种密切相关的方法。我不明白为什么GraphType的第一个typedef似乎在工作,而VertexType的第二个则失败了。
#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;
}
编译器输出:
$ 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’
同样的事情,只是避免在第二个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;
}
编译器输出看起来实际上是一样的:
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’
显然,第一个编译器错误是根本问题。我尝试在一些地方插入typename
,但没有成功。我使用的是gcc 4.2.1
我该如何解决这个问题?
typedef typename boost::graph_traits<GraphType>::vertex_descriptor VertexType;
// ^^^^^^^^
应该把它修好,不过我不知道你想把它放在哪里。。你可能还有其他问题,我看不出来。
相关文章:
- 理解boost::asio-async_read在无需读取内容时的行为
- C++:TypeDef使用元组
- boost::进程间消息队列引发错误
- 如何运行位于boost/libs/python/example/tutorial目录中的hello.cpp和Jamfil
- cmake如何在fedora工作站中找到boost静态库包
- CMake项目Boost库错误:Boost/config/compiler/gcc.hpp:165:10:致命错误:cs
- Boost Graph Library,修复节点大小
- 什么是"#include <boost/functional/hash.hpp> "?
- 基于boost的程序的静态链接——zlib问题
- C++:如何在CLion IDE中安装Boost
- C++Boost Asio Pool线程,带有lambda函数和传递引用变量
- typedef 一个向量和 boost::numeric::ublas::vector 的固定大小
- BOOST.PYTHON如何公开boost :: shared_ptr的Typedef
- 模板函数的'typedef' (boost::make_shared)
- 如何在编译时检查两种类型是否相同(奖励点是否可与Boost strong typedef一起使用)
- 使用强typedef作为Boost参数库的更轻量级的替代方案
- Boost: typedef for rpm
- 拥有typedef std::map<boost::<my_class>shared_ptr,my_description>如何从我的函数返回和shared_ptr?
- 使用boost图库的模板typedef汤
- 如何投射到它 boost::bind(&myClass::fun, this, _1, _2, _3) 到 typedef void (*fun)(arg1, arg2, arg3)?