I get an error in Xcode when using templates in C ++. Can someone tell me what is wrong?
The first version reports an error in Xcode, but not in Visual Studio.
// Version 1: Error in Xcode, but not Visual Studio template<typename LengthT, typename VertexT> int MyGraphAlgorithm(...arguments omitted...) { using namespace boost; typedef property<vertex_distance_t, LengthT> VertextProperties_t; typedef adjacency_list<vecS, vecS, directedS, VertextProperties_t> Graph; // In next line Xcode reports: "error: expected `;' before 'vertexInitial'" graph_traits<Graph>::vertex_descriptor vertexInitial(100); }
The second error has not. The difference lies in using the LengthT template parameter in the typedef template.
// Version 2: No error in Xcode or Visual Studio template<typename LengthT, typename VertexT> int MyGraphAlgorithm(...arguments omitted...) { using namespace boost; // In the following line, LengthT has been changed to int typedef property<vertex_distance_t, int> VertextProperties_t; typedef adjacency_list<vecS, vecS, directedS, VertextProperties_t> Graph; graph_traits<Graph>::vertex_descriptor vertexInitial(100); }
source share