看代码选择答案—类模板的实例化
考点:类模板的实例化的理解
出现频率:★★★★
1 template<class T, int size = 10>
2 class Array {
3 …
4 };
5 void foo( )
6 {
7 Array <int> arr1;
8 Array <char> arr4, arr5;
9 Array <int> arr2, arr3;
10 Array <double> arr6;
11 …
12 }
How many instances of the template class Array will get instantiated inside the function foo()
A 3 B 6 C 4 D 1
解析:
模板类(template class)的实例个数是由类型参数的种类决定的。代码7行和9行实例化的模板类都是Array<int, 10>,代码8行实例化的模板类是Array<char, 10>,代码10行实例化的模板类是Array<double, 10>。一共是三个实例。
答案:
A