簡體   English   中英

為什么<>在鄰接表<>中為空

[英]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
{
    ...
}

請注意,每個模板參數都有一個默認值: vecSvecSdirectedSno_propertyno_propertyno_propertylistS

空的<>表示您想要模板參數的默認類。 通過不指定模板參數的特定值,可以得到默認值。

需要<>且不能將其忽略的原因(這很好,是的)是因為C ++語言的定義方式。 您可以使用typedef來避免這種情況 ,但是最終使用模板類型需要使用尖括號。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM