在C++中使用模板时,出现Xcode错误。有人能告诉我什么是错的吗?为什么这个模板在Xcode中有错误,但不是Visual Studio?
第一个版本在Xcode中报告错误,但在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);
}
第二个没有错误。区别在于在模板化类型定义中使用模板参数LengthT。
// 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);
}
修复它,谢谢。 – gauss256 2010-07-30 05:43:10