How to solve Boost :: BGL template & # 8596; cyclic class dependency?

I'm having a problem using the Boost Graphics Library adjacency list. This seems to be a circular dependency problem: I have a typedef T of a template that uses some class A. In addition, A stores a pointer to an object of type T. Now the compiler tells me that T does not name the type.

Here are excerpts from my more specific 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 to solve this addiction / inclusion problem?

: , edge_descriptor , int. , edge_descriptors Lane int- , , graphdefinitions.hpp tie.hpp. , , . , Edge_descriptor - ...

+3
4

. Lane , , .. .

Edit: , OP. - PIMPL.

: , , - typedef Lane. .

0

BGL - , adjacency_list, . . " " http://www.boost.org/doc/libs/1_45_0/libs/graph/doc/adjacency_list.html , vertex_descriptor edge_descriptor; , adjacency_list_traits , .

+7

, - . , , , ( ).

0

@DeadMG: , PIMPL, , .

? Lane, :

//lane.hpp
#include "graphdefinitions.hpp"

class LaneSide;
class Lane {
public:
    const LaneSide getLeft() const;
    const LaneSide getRight() const;
    ...
private:
    LaneSide *left;
    LaneSide *right;
    ...
};

LaneSide, , , lane.hpp, :

//laneside.hpp
class LaneSide
{
    edge_descriptor* edge;
};

This seems to be a compiler trick, as I expected. So thanks for the help from DeadMG. What interests me is: is it also possible to save the LaneSide object inside the Lane class not as a pointer, but rather as a real object? I tried this first, but the compiler complained about the construction. And I'm also wondering if there could be a way to avoid the extra memory consumption. When my schedule gets big enough, it can become relevant over time.

0
source

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


All Articles