如何修改訪問者內部頂點的綁定屬性?從訪問者修改綁定屬性
我想用子腳本的曲線圖的簡單的方法,但傳遞到訪問者圖形參數是常量,所以編譯器不允許改變。
我可以在訪問者中存儲對圖形的引用,但這看起來很奇怪。
/**
A visitor which identifies vertices as leafs or trees
*/
class bfs_vis_leaf_finder:public default_bfs_visitor {
public:
/**
Constructor
@param[in] total reference to int variable to store total number of leaves
@param[in] g reference to graph (used to modify bundled properties)
*/
bfs_vis_leaf_finder(int& total, graph_t& g) :
myTotal(total), myGraph(g)
{
myTotal = 0;
}
/**
Called when the search finds a new vertex
If the vertex has no children, it is a leaf and the total leaf count is incremented
*/
template <typename Vertex, typename Graph>
void discover_vertex(Vertex u, Graph& g)
{
if(out_edges(u, g).first == out_edges(u, g).second) {
myTotal++;
//g[u].myLevel = s3d::cV::leaf;
myGraph[u].myLevel = s3d::cV::leaf;
} else {
//g[u].myLevel = s3d::cV::tree;
myGraph[u].myLevel = s3d::cV::tree;
}
}
int& myTotal;
graph_t& myGraph;
};
我開始認爲eaoring的參考必須的方式。我認爲我忽略了一些簡單的東西,但是由於目前還沒有人提出任何其他建議...... – ravenspoint 2009-10-13 21:44:06