2011-06-21 90 views
0

您好我有一個像升壓圖:加速圖形遞歸模板問題

struct Vertex; 
struct Edge; 



typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t; 


struct Vertex { 
}; 

struct Edge { 
    typedef std::vector<Graph_t::vertex_descriptor> intermediate_vertices_t; 
    intermediate_vertices_t intermediate_vertices; 
}; 

的問題是,在邊緣類遞歸模板。我需要存儲一個頂點向量。

+0

你確定你有'Graph_t'右邊的模板參數嗎?第四個和第五個參數是_properties_,而不是頂點和邊的類本身......你必須爲頂點和邊集合提供一個合適的容器,'boost :: adjacency_list :: vertex_descriptor'只是指向那個類型的值容器(或多或少)。 –

+0

你使用什麼編譯器。我已經編譯並在VC++ 2010中運行你的代碼沒有任何問題 – Eugene

回答

0

我結束了使用小包裝類,如:

typedef Graph_t::vertex_descriptor vd_t;       

struct iVertexWrap{             
    iVertexWrap(vd_t v) : v(v) 
    {}                
    vd_t v; 
}; 

邊緣課前向前聲明它。

2

您可以使用adjacency_list_traits來解決此問題。該類允許用戶訪問頂點和邊描述符類型,而不需要用戶爲圖提供屬性類型。

struct Vertex { 
}; 

typedef boost::adjacency_list_traits<boost::vecS, boost::vecS, boost::bidirectionalS>::vertex_descriptor VertexDescriptor; 
struct Edge { 
    typedef std::vector<VertexDescriptor> intermediate_vertices_t; 
    intermediate_vertices_t intermediate_vertices; 
}; 
typedef boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, Vertex, Edge> Graph_t;