简体   繁体   中英

Why does g++ complain when using templated typedefs in graph_traits<>?

When I try to compile this code:

struct BasicVertexProperties
{
    Vect3Df position;
};

struct BasicEdgeProperties
{
};

template < typename VERTEXPROPERTIES, typename EDGEPROPERTIES >
class Graph
{
    typedef adjacency_list<
        setS, // disallow parallel edges
        vecS, // vertex container
        bidirectionalS, // directed graph
        property<vertex_properties_t, VERTEXPROPERTIES>,
        property<edge_properties_t, EDGEPROPERTIES>
    > GraphContainer;

    typedef graph_traits<GraphContainer>::vertex_descriptor Vertex;
    typedef graph_traits<GraphContainer>::edge_descriptor Edge;
};

g++ complains with the following error in the "typedef graph_traits<>" line:

error: type 'boost::graph_traits<boost::adjacency_list<boost::setS, boost::vecS, 
boost::bidirectionalS, boost::property<vertex_properties_t, VERTEXPROPERTIES, 
boost::no_property>, boost::property<edge_properties_t, EDGEPROPERTIES, 
boost::no_property>, boost::no_property, boost::listS> >' is not derived from type 
'Graph<VERTEXPROPERTIES, EDGEPROPERTIES>'

I found out that the compiler seems not to know that my template parameters are types, but putting "typename" before them in the property definition doesn't help.

What is wrong? I simply want to have a templated Graph class to have the possibility to use whatever properties I like, derived from the basic property structs defined above, so I can have methods in this Graph that operate on the basic properties.

These lines:

    typedef graph_traits<GraphContainer>::vertex_descriptor Vertex;
    typedef graph_traits<GraphContainer>::edge_descriptor Edge;

should be:

    typedef typename graph_traits<GraphContainer>::vertex_descriptor Vertex;
    typedef typename graph_traits<GraphContainer>::edge_descriptor Edge;

The reason being that the compiler cant not tell that vertex_descriptor is a type until the point where you define what GraphContainer is (as the one could potentially be defined in terms of the other).

This the standard requires you to specify that this is a type rather than a static member variable.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM