Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/templates/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 使用boost图形库的模板化typedef汤_C++_Templates_Boost_Typedef - Fatal编程技术网

C++ 使用boost图形库的模板化typedef汤

C++ 使用boost图形库的模板化typedef汤,c++,templates,boost,typedef,C++,Templates,Boost,Typedef,我试图创建一个类,该类扩展boost图形库的行为。我希望我的类是一个模板,其中用户提供一个类型(类),用于存储每个顶点的属性。那只是背景。我正在努力创建一个更简洁的typedef来定义我的新类 基于和等其他帖子,我决定定义一个包含模板化typedef的结构 我将展示两种密切相关的方法。我不明白为什么GraphType的第一个typedef似乎在工作,而VertexType的第二个却失败了 #包括 #包括 样板 结构图形类型 { typedef boost::邻接列表图形类型; typedef b

我试图创建一个类,该类扩展boost图形库的行为。我希望我的类是一个模板,其中用户提供一个类型(类),用于存储每个顶点的属性。那只是背景。我正在努力创建一个更简洁的typedef来定义我的新类

基于和等其他帖子,我决定定义一个包含模板化typedef的结构

我将展示两种密切相关的方法。我不明白为什么GraphType的第一个typedef似乎在工作,而VertexType的第二个却失败了

#包括
#包括
样板
结构图形类型
{
typedef boost::邻接列表图形类型;
typedef boost::graph_traits::顶点描述符VertexType;
};
int main()
{
GraphTypes::GraphTypeAgraphInstance;
GraphTypes::VertexType aVertexInstance;
返回0;
}
编译器输出:

$ g++ -I/Developer/boost graph_typedef.cpp 
graph_typedef.cpp:8: error: type ‘boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP, boost::no_property, boost::no_property, boost::listS> >’ is not derived from type ‘GraphTypes<VP>’
graph_typedef.cpp:8: error: expected ‘;’ before ‘VertexType’
graph_typedef.cpp: In function ‘int main()’:
graph_typedef.cpp:14: error: ‘VertexType’ is not a member of ‘GraphTypes<int>’
graph_typedef.cpp:14: error: expected `;' before ‘aVertexInstance’
编译器输出看起来基本相同:

g++ -I/Developer/boost graph_typedef.cpp 
graph_typedef.cpp:8: error: type ‘boost::graph_traits<boost::adjacency_list<boost::vecS, boost::vecS, boost::bidirectionalS, VP, boost::no_property, boost::no_property, boost::listS> >’ is not derived from type ‘GraphTypes<VP>’
graph_typedef.cpp:8: error: expected ‘;’ before ‘VertexType’
graph_typedef.cpp: In function ‘int main()’:
graph_typedef.cpp:14: error: ‘VertexType’ is not a member of ‘GraphTypes<int>’
graph_typedef.cpp:14: error: expected `;' before ‘aVertexInstance’
g++-I/Developer/boost图_typedef.cpp
graph_typedef.cpp:8:错误:类型“boost::graph_traits”不是从类型“GraphTypes”派生的
图形_typedef.cpp:8:错误:应为“;”在“VertexType”之前
graph_typedef.cpp:在函数“int main()”中:
graph_typedef.cpp:14:错误:“VertexType”不是“GraphTypes”的成员
图形_typedef.cpp:14:错误:应为`;'在“避免存在”之前
显然,第一个编译器错误是根本问题。我尝试在几个地方插入
typename
,但没有成功。我使用的是GCC4.2.1

如何修复此问题?

typedef typename boost::graph\u traits::VertexType;
typedef typename boost::graph_traits<GraphType>::vertex_descriptor VertexType;
//      ^^^^^^^^
// ^^^^^^^^

如果你能修好的话,我不知道你想把它放在哪里。。你可能还有其他我看不到的问题。

哦,天哪,是的,这很有效。不过,这将是我最不愿意抛出typename标记的地方。当然,typedef关键字后面的第一个参数应该是typename。@Noah:确切地说,它必须直接位于依赖名称(嵌套的typedef或类/结构)之前。