模板函數問題
在VC下定義一個
估計應該是編譯器不知道list<T*>::iterator是代表一個類型
還是代表list<T*>類中的一個成員,叫做iterator
1
template<typename T>
2
list<T>::iterator seqSearch( list<T>::iterator first, list<T>::iterator last, const T& target)
3
{
4
list<T>::iterator iter = first;
5
while (iter != last &&(*iter != target))
6
++iter;
7
return iter;
8
}
但是始終無法通過編譯,最后改為
2

3

4

5

6

7

8

1
template<typename T>
2
typename list<T>::iterator seqSearch(typename list<T>::iterator first, typename list<T>::iterator last, typename const T& target)
3
{
4
list<T>::iterator iter = first;
5
while (iter != last &&(*iter != target))
6
++iter;
7
return iter;
8
}
就好了 
2

3

4

5

6

7

8

估計應該是編譯器不知道list<T*>::iterator是代表一個類型
還是代表list<T*>類中的一個成員,叫做iterator
posted on 2008-08-20 16:56 大海 閱讀(842) 評論(3) 編輯 收藏 引用 所屬分類: stl
posted on 2008-08-31 21:34 肥仔 閱讀(275) 評論(0) 編輯 收藏 引用 所屬分類: C++ 模板