views:

248

answers:

1

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.

+6  A: 

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.

Martin York
That's because compiler can't figure out what is ::vertex_description and ::edge_description, with typedef typename you're telling him that graph_traits<>::vertex_description is a type
stefanB