16.17 在模板参数列表中,typename和class含义相同,typename比class更直观,因为内置类型也可以作为模板类型实参。当使用作用域运算符(::)访问一个模板类型参数的成员时,该成员可能是静态成员,也可能是类型成员,为了区分这点,需要在名字前使用typename关键字,指明其是一个类型。
16.18 (a)非法。U是类型参数,必须加上typenmae关键字;(b)非法。在作用域中,模板参数不能重用,这里用T当作参数名使用,错误;(c)非法。模板在定义时才能使用inline;(d)非法。没有返回值;(e)合法,但是模板声明的Ctype隐藏了类型别名Ctype。
16.19
#include <iostream>
#include <vector>
using namespace std;
template <typename T>
void Print(const T &con)
{
for (typename T::size_type i = 0; i != con.size(); i++)
cout << con.at(i) << endl;
}
int main()
{
vector<int> ivec = {1, 2, 3, 5, 7, 11};
Print(ivec);
return 0;
}
16.20
#include <iostream>
#include <deque>
using namespace std;
template <typena