2013-07-11 84 views
1

我在嘗試boost :: graph頭文件庫,但我仍然無法將垂直線添加到我的圖中。boost :: graph add_vertex編譯錯誤

這是我如何使用add_vertex功能:

void GraphManager::addToGraph(VertexProperties node){ 

    //no error, but i do not need it 
    vertex_t v = boost::add_vertex(graph); 

    //compilation error 
    vertex_t v = boost::add_vertex(node, graph); 

    /*...*/ 
} 

我的定義在這裏:

#ifndef GRAPH_DEFINITION_H 
#define GRAPH_DEFINITION_H 

#include <boost/graph/adjacency_list.hpp> 
#include "matchedword.h" 

typedef MatchedWord* VertexProperties; 

struct EdgeProperties 
{ 
    int distance; 
    EdgeProperties() : distance(0) {} 
    EdgeProperties(int d) : distance(d) {} 
}; 

struct GraphProperties { 

}; 

typedef boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::undirectedS, 
    boost::property<VertexProperties, boost::vertex_bundle_t>, 
    boost::property<EdgeProperties, boost::edge_bundle_t>, 
    boost::property<GraphProperties, boost::graph_bundle_t> 
> Graph; 

typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t; 
typedef boost::graph_traits<Graph>::edge_descriptor edge_t; 


#endif // GRAPH_DEFINITION_H 

任何想法? 謝謝。

error: no matching function for call to 'add_vertex(MatchedWord*&, Graph&)' candidates are: [...] template typename Config::vertex_descriptor boost::add_vertex(const typename Config::vertex_property_type&, boost::adj_list_impl&)

note: template argument deduction/substitution failed:

note: 'Graph {aka boost::adjacency_list, boost::property, boost::property >}' is not derived from 'boost::adj_list_impl'

我不明白這個錯誤輸出的意思。

+0

它基本上是說您試圖調用的函數與您放置的參數不存在,但有一個版本具有不同的參數。即該函數存在,但沒有與您提供的參數相匹配的版本。 – refi64

+0

更確切地說,它說,原因是我作爲參數傳遞的圖不是從'boost :: adj_list_impl'派生的。然而,'boost :: add_vertex(boost :: adj_list_impl)'在傳遞我的圖時不起作用,但不是'boost :: add_vertex(boost:vertex_property_type&,boost :: adj_list_impl&)'... – Vulpo

回答

1

Ravenspoint指定綁定屬性,你是對的,我只是濫用捆綁屬性。

這裏是我的代碼,它現在的作品:)

#ifndef GRAPH_DEFINITION_H 
#define GRAPH_DEFINITION_H 

#include <boost/graph/adjacency_list.hpp> 
#include "matchedword.h" 

struct VertexProperties { 
public : 
    MatchedWord* matchedWord; 
}; 

struct EdgeProperties 
{ 
    int distance; 
    EdgeProperties() : distance(0) {} 
    EdgeProperties(int d) : distance(d) {} 
}; 

struct GraphProperties { 

}; 

typedef boost::adjacency_list< 
    boost::vecS, boost::vecS, boost::undirectedS, 
    VertexProperties, 
    EdgeProperties, 
    GraphProperties 
> Graph; 

typedef boost::graph_traits<Graph>::vertex_descriptor vertex_t; 
typedef boost::graph_traits<Graph>::edge_descriptor edge_t; 


#endif // GRAPH_DEFINITION_H 

被調用的函數(也許我以後再返工的定義)是:

void GraphManager::addToGraph(VertexProperties node){ 
    vertex_t v = boost::add_vertex(graph); 
    graph[v].matchedWord = node.matchedWord; 
} 

謝謝您的回答一切!

+0

如果您回答了您自己的問題,請接受答案。如果你喜歡ravespoint的答案,接受那個。 – refi64

3

使用捆綁屬性更容易。

事情是這樣的:

// A class to hold bundled properties for a vertex 
// In this case, we have a pointer to a MatchedWord object 

class vertex_props { 
public: 
MatchedWord * pMW; 
}; 

定義的圖表類型捆綁性

typedef boost::adjacency_list< 
boost::vecS, boost::vecS, boost::undirectedS, 
vertex_props, 
... 
> Graph_t; 

現在你可以添加一個頂點,像這樣

void GraphManager::addToGraph(MatchedWord * node){ 
    graph[ boost::add_vertex(graph) ].pMW = node; 
    ... 
+0

VertexProperties中捆綁的matchedWord * boost :: add_vertex(graph).matchedWord = node;不起作用,因爲add_vertex返回一個vertex_descriptor。所以我試過: vertex_t v = boost :: add_vertex(graph); graph [v] .matchedWord = node; 但它仍然無效:「boost :: adjency_list <...> :: vertex_bundle沒有名爲matchedWord的成員」! (它有) – Vulpo

+0

不能確定沒有看到你的代碼,但它聽起來像你沒有定義你的圖形類型使用捆綁屬性。請發佈您的代碼。 – ravenspoint