c – 为什么在graph_traits <>中使用模板化typedef时会抱
发布时间:2020-12-16 09:23:56 所属栏目:百科 来源:网络整理
导读:当我尝试编译此代码时: struct BasicVertexProperties{ Vect3Df position;};struct BasicEdgeProperties{};template typename VERTEXPROPERTIES,typename EDGEPROPERTIES class Graph{ typedef adjacency_list setS,// disallow parallel edges vecS,// ver
当我尝试编译此代码时:
struct BasicVertexProperties { Vect3Df position; }; struct BasicEdgeProperties { }; template < typename VERTEXPROPERTIES,typename EDGEPROPERTIES > class Graph { typedef adjacency_list< setS,// disallow parallel edges vecS,// vertex container bidirectionalS,// directed graph property<vertex_properties_t,VERTEXPROPERTIES>,property<edge_properties_t,EDGEPROPERTIES> > GraphContainer; typedef graph_traits<GraphContainer>::vertex_descriptor Vertex; typedef graph_traits<GraphContainer>::edge_descriptor Edge; }; g抱怨“typedef graph_traits<>”中出现以下错误线: error: type 'boost::graph_traits<boost::adjacency_list<boost::setS,boost::vecS,boost::bidirectionalS,boost::property<vertex_properties_t,VERTEXPROPERTIES,boost::no_property>,boost::property<edge_properties_t,EDGEPROPERTIES,boost::no_property,boost::listS> >' is not derived from type 'Graph<VERTEXPROPERTIES,EDGEPROPERTIES>' 我发现编译器似乎不知道我的模板参数是类型,但在属性定义中将“typename”放在它们之前并没有帮助. 怎么了?我只是希望有一个模板化的Graph类,可以使用我喜欢的任何属性,从上面定义的基本属性结构派生,所以我可以在这个Graph中使用基本属性的方法. 解决方法
这些线:
typedef graph_traits<GraphContainer>::vertex_descriptor Vertex; typedef graph_traits<GraphContainer>::edge_descriptor Edge; 应该: typedef typename graph_traits<GraphContainer>::vertex_descriptor Vertex; typedef typename graph_traits<GraphContainer>::edge_descriptor Edge; 原因是编译器不能告诉vertex_descriptor是一个类型,直到你定义GraphContainer是什么(因为一个可能用另一个来定义). 此标准要求您指定这是一个类型而不是静态成员变量. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |