如何解决Boost :: BGL模板< - >类循环依赖? [英] How to solve Boost::BGL template<->class circular dependency?
问题描述
我有一个使用Boost图形库的邻接表的问题。它似乎是一个循环依赖问题:
我有一个模板的typedef T使用一些类A.另外A存储一个指向一个类型T的对象的指针。现在编译器告诉我,T不命名
I have a problem with using the adjacency-list of the Boost Graphics Library. It seems to be a circular dependency problem: I have a typedef T of a template which uses some class A. Additionally A stores a pointer to an object of type T. Now the compiler tells me, that T does not name a type.
这里是我更具体文件的例子:
Here are excerptions of my more concrete files:
//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 {
...
};
如何解决这个依赖/包含顺序问题?
How do I solve this dependency / inclusion-order problem?
另一个编辑:
我只是想到一个edge_descriptor类型可能是一个像int的原始类型。这将解决这个问题,因为我将能够替换Lane的edge_descriptors通过纯int变量,因此可以删除包含graphdefinitions.hpp在tie.hpp。不幸的是,我的想法是cra *,我必须找到另一个解决方案。 Edge_descriptor类型似乎存在的原因...
ANOTHER I just had the idea that the type of an edge_descriptor might be a primitive one like int. That would have solved the problem because I would have been able to replace the edge_descriptors of Lane by plain int-variables and thus could have removed the inclusion of graphdefinitions.hpp inside tie.hpp. Unfortunately my idea was cra* and I have to find another solution. Edge_descriptor types seem to be there for a reason...
推荐答案
Lane包括graphdefinitions,其中包括lane,包括graphdefinitions等。这是你的问题的原因。
You have circularly included headers. Lane includes graphdefinitions, which includes lane, which includes graphdefinitions, etc. This is the cause of your problem.
编辑:我意识到这已经在OP中提到。这个问题的解决方案是PIMPL。
I realized this was already mentioned in the OP. The solution to this problem is PIMPL.
编辑:我实际上是把typedef放在Lane类中。这应该以最简洁的方式解决问题。
What I would actually do is put the typedef inside the Lane class. That should solve the problem in the neatest way.
这篇关于如何解决Boost :: BGL模板< - >类循环依赖?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!