我使用的是Stroustrup C ++第4版第692页的示例。有人知道为什么typename
必须先于Iter::value_type
吗?特别是对于第二个mean
函数,为什么此模板函数不需要typename
?
我已经按顺序阅读了Stroustrup的书,并且位于模板部分。我不记得阅读过有关其背后原因的文章。
感谢您的指导!
template<typename Iter>
typename Iter::value_type mean(Iter first, Iter last);
template<typename T>
T mean(T*,T*);
void f(vector<int>& v, int* p, int n)
{
auto x = mean(v.begin(),v.end());
auto y = mean(p,p+n);
}