今天寫一個模板類,出于的目的是要寫的模板類原本是兩個管理類,里面除了被管理的類不同之外其他全部相同,但是今后可能兩者會被擴(kuò)充,如果寫成一個就不好的。
后來想想還是把它改寫成為一個模板類才行。
在類當(dāng)中有一個std::list的成員,我要定義一個訪問器:

std::list<T*>::iterator begin()
{return list.begin();};
但是結(jié)果是出現(xiàn)類似如下的編譯錯誤:
error: type `std::vector<T, std::allocator<_CharT>; >;' is not derived from type `Record<T>;'
error: ISO C++ forbids declaration of `iterator' with no type
后來查到了,原來要在之前加一個
typename。
正確代碼如下:
typename std::list<T*>::iterator iter;
