在尝试将一些 boost 图形代码重构为函数模板时,我遇到了一些编译错误。
我正在尝试将该using NODE_TYPE = int;
行移动到函数模板参数中。
我究竟做错了什么?
编译错误
Test_Dijkstra_Graph.cpp:48:28: error: expected type-specifier
Test_Dijkstra_Graph.cpp:48:28: error: expected ‘;’
Test_Dijkstra_Graph.cpp:49:28: error: expected type-specifier
Test_Dijkstra_Graph.cpp:49:28: error: expected ‘;’
旧代码编译得很好
void
find_shortest_paths_by_pairs()
{
using NODE_TYPE = int;
using EDGE = std::pair<NODE_TYPE,NODE_TYPE>;
using GRAPH_T = adjacency_list<
listS, vecS, directedS, no_property, property< edge_weight_t, NODE_TYPE >>;
using vertex_descriptor = graph_traits<GRAPH_T>::vertex_descriptor;
using edge_descriptor = graph_traits<GRAPH_T>::edge_descriptor;
// ...
}
新代码无法编译
template<typename NODE_TYPE>
void find_shortest_paths_by_pairs()
{
using EDGE = std::pair<NODE_TYPE,NODE_TYPE>;
using GRAPH_T = adjacency_list<
listS, vecS, directedS, no_property, property< edge_weight_t, NODE_TYPE >>;
using vertex_descriptor = graph_traits<GRAPH_T>::vertex_descriptor; // ERROR HERE
using edge_descriptor = graph_traits<GRAPH_T>::edge_descriptor; // ERROR HERE
// ...
}
// find_shortest_paths_by_pairs<int>();