[英]c++ confusion about embedding a struct name in itself
我正在學習boost,這是來自以下代碼的一段: http : //www.boost.org/doc/libs/1_55_0/libs/graph/example/visitor.cpp我對struct edge_printer
的定義確實感到困惑,它使用base_visitor
的繼承,但是base_visitor
模板的類型名稱指定為edge_printer
本身。 請問這在C ++中是什么?
template <class Tag>
struct edge_printer : public base_visitor<edge_printer<Tag> > {
typedef Tag event_filter;
edge_printer(std::string edge_t) : m_edge_type(edge_t) { }
template <class Edge, class Graph>
void operator()(Edge e, Graph& G) {
std::cout << m_edge_type << ": " << source(e, G)
<< " --> " << target(e, G) << std::endl;
}
std::string m_edge_type;
};
template <class Tag>
edge_printer<Tag> print_edge(std::string type, Tag) {
return edge_printer<Tag>(type);
}
這稱為混合。 參見CRTP和有關mixins的文章 。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.