在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