2013-04-02 182 views
0

我有這樣的功能:模板函數不編譯

template<template <class _Ty, class _A = allocator<_Ty> > class Container> 
    static void FreeAttributesVS(const Container<int>& arra) 
    { 
     for(Container<int>::const_iterator iter = arra.begin(); 
      iter != arra.end(); ++iter) 
     { 
      //do smthng 
     } 
    } 

它編譯在VisualStudio中,但在Eclipse編譯器說"Invalid template argumetns",我該怎麼辦?

+0

對於哪一行沒有說是什麼? – 0x499602D2

+0

第一行當我將鼠標懸停在分配器<_Ty>以上時,它還會顯示「類型_Ty無法解析」 –

+0

它是否編譯*? –

回答

2

您需要typenameContainer<int>::const_iterator之前,因爲這是一個依賴型:

static void FreeAttributesVS(const Container<int>& arra) 
{ 
    for (typename Container<int>::const_iterator iter = arra.begin(); ...) 
    // ^^^^^^^ 

} 
+0

這裏實際上並不是一個依賴類型,因爲模板參數是已知的('int')。 – juanchopanza

+0

@juanchopanza但'Container'是一個模板參數。 – 0x499602D2

+0

啊,是的,你說得對。 – juanchopanza