【发布时间】:2014-06-04 15:37:03
【问题描述】:
简短的问题描述:
基本上我想要
struct Type;
typedef container<Type> MyType;
struct Type{
MyType::sometype member;
}
现在,我该怎么做?
实际问题:
对于Boost Succesive Shortest Path 算法,我需要将我的前向边缘映射到它们的反向。我有以下代码:
struct VertexProperty { };
struct EdgeProperty;
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::directedS, VertexProperty, EdgeProperty> DirectedGraph;
struct EdgeProperty {
double edge_capacity; //capacity: 1 for forward, 0 for reverse
double edge_weight; //cost
DirectedGraph::edge_descriptor reverse_edge; //reverse edge mapping
//forward edge constructor:
EdgeProperty(double distance, DirectedGraph::edge_descriptor reverseEdge) :
edge_capacity(1), edge_weight(distance), reverse_edge(reverseEdge) {
};
//reverse edge constructor
EdgeProperty(double distance) :
edge_capacity(0), edge_weight(-distance) {
};
};
但是,现在我收到以下错误:
/usr/include/boost/pending/property.hpp:35:7: error: ‘boost::property<Tag, T, Base>::m_value’ has incomplete type
../src/Tester.cpp:21:8: error: forward declaration of ‘struct EdgeProperty’
我想这是有道理的:对于 DirectedGraph::edge_descriptor,我需要 EdgeProperty 的完整类型,但它当然没有初始化。如何解决此循环引用?
【问题讨论】:
-
@aschepler 这很可能是我的问题的解决方案......我现在正在尝试。
-
@aschepler 是的,就是这样!如果您将其作为答案发布,我会接受它作为解决方案 xD
标签: c++ boost forward-declaration circular-reference