![](/img/trans.png)
[英]Is there a simple way to find out if a boost::adjacency_list is empty?
[英]why <> is empty in adjacency_list<>
我可以問adjacency_list<>
的<>
是什么嗎? 我是stl的新手。 我知道我可以這樣定義一個容器: vector<int> vec
,但是為什么在<>
它是空的? 謝謝。
#include <boost/graph/adjacency_list.hpp>
using namespace boost;
adjacency_list<> g;
// adds four vertices to the graph
adjacency_list<>::vertex_descriptor v1 = add_vertex(g);
adjacency_list<>::vertex_descriptor v2 = add_vertex(g);
adjacency_list<>::vertex_descriptor v3 = add_vertex(g);
adjacency_list<>::vertex_descriptor v4 = add_vertex(g);
這是因為adjacency_list
是模板化類型 。 使用C ++模板時必須指定<>
。
該類型的完整定義為:
template <class OutEdgeListS = vecS,
class VertexListS = vecS,
class DirectedS = directedS,
class VertexProperty = no_property,
class EdgeProperty = no_property,
class GraphProperty = no_property,
class EdgeListS = listS>
class adjacency_list
{
...
}
請注意,每個模板參數都有一個默認值: vecS
, vecS
, directedS
, no_property
, no_property
, no_property
, listS
。
空的<>
表示您想要模板參數的默認類。 通過不指定模板參數的特定值,可以得到默認值。
需要<>
且不能將其忽略的原因(這很好,是的)是因為C ++語言的定義方式。 您可以使用typedef
來避免這種情況 ,但是最終使用模板類型需要使用尖括號。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.