我在使用 Boost 图形库的邻接列表时遇到问题。这似乎是一个循环依赖问题:我有一个模板的 typedef T,它使用了某个类 A。另外,A 存储了一个指向 T 类型对象的指针。现在编译器告诉我,T 没有命名一个类型。
以下是我更具体的文件的摘录:
//graphdefinitions.hpp
#include "lane.hpp"
#include "tie.hpp"
typedef boost::adjacency_list<boost::listS, boost::listS,
boost::directedS, Tie, Lane> Map;
typedef boost::graph_traits<Map>::edge_descriptor edge_descriptor;
//lane.hpp
#include "graphdefinitions.hpp"
class Lane {
...
edge_descriptor *left, *right;
};
//tie.hpp
//no important includes here
class Tie {
...
};
如何解决这个依赖/包含顺序问题?
另一个编辑:我只是想到 edge_descriptor 的类型可能是像 int 这样的原始类型。这将解决问题,因为我可以用普通的 int 变量替换 Lane 的 edge_descriptors,因此可以删除 tie.hpp 中包含的 graphdefinitions.hpp。不幸的是,我的想法很糟糕,我必须找到另一个解决方案。Edge_descriptor 类型似乎是有原因的......