Forward structure declaration for Boost graph typedef C ++

Short description of the problem:

Basically i want

struct Type;
typedef container<Type> MyType;
struct Type{
    MyType::sometype member;
}

Now how to do it?

Actual problem:

For the Boost Succesive Shortest Path algorithm, I need the front edges to map to their opposite. I have the following code:

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) {
    };

};

However, now I get the following error:

/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’

I assume this makes sense: for DirectedGraph :: edge_descriptor I need the full type of EdgeProperty, but this one, of course, is not initialized. How to solve this circular link?

+4
source share
1 answer

, struct Type ( ) until container<Type> , struct Type...., .

, , .

:

#include <vector>
#include <memory>

struct Type;
typedef std::vector<Type> MyType;
struct Type{
    std::shared_ptr<MyType::value_type> member;
};

int main() {
        Type t;
}

? ...

+1

Source: https://habr.com/ru/post/1543234/


All Articles