2
我有具有取決於類型作爲用作函數參數的typedef模板類依賴型爲函數參數的聲明在類Foo
之外正確聲明功能bar()
的意見。在模板類
我originately寫這樣在Linux上,這GCC愉快編譯:
template <typename T>
inline void Foo<T>::bar(const Foo<T>::Iterator& it) const {}
現在試圖編譯上的Visual Studio 2015年,我得到的
1>main.cpp(14): error C2065: 'it': undeclared identifier
1>main.cpp(14): warning C4346: 'Foo<T>::Iterator': dependent name is not a type
1> main.cpp(14): note: prefix with 'typename' to indicate a type
所以出現以下錯誤消息該VS要求typename
關鍵字出現在Iterator
之前。精細。我添加了它,但現在它拒絕在GCC中編譯。
main.cpp:14:35: error: variable or field 'bar' declared void
inline void Foo<T>::bar(typename const Foo<T>::Iterator& it) const {}
你可以看到它住在這裏http://ideone.com/EaUeus
所以我的問題是......誰是正確的?有沒有辦法讓這個代碼在兩個平臺上編譯而不需要使用#ifdef
?
啊,我應該想到這件事的人,你是對的。接得好。 – Louen