正在加载图片...
接1例6.2 int int array={1,2,34,5,6,78,9,10} double double array={1122,3344,55667788,9910.10} void maino int itotal=sum(int array, 10) double dtotalsum(double array, 10) cout<< The summary of integer array are: <<itotal<<endl cout<<,The summary of double array are: <<dtotal<<end; 程序运行结果为: The summary of integer array are: 55 The summary of double array are: 59.6 几点说明: (1)在函数模板中允许使用多个类型参数。但在 template定义部分的 每个模板形参前必须有关键字 class。接1 例6.2 int int_array[]={1,2,3,4,5,6,7,8,9,10}; double double_array[]={1.1,2.2,3.3,4.4,5.5,6.6,7.7,8.8,9.9,10.10}; void main() { int itotal=sum(int_array,10); double dtotal=sum(double_array,10); cout<<”The summary of integer array are:” <<itotal<<endl; cout<<”The summary of double array are:” <<dtotal<<endl; } 程序运行结果为: The summary of integer array are:55 The summary of double array are:59.6 几点说明: ⑴在函数模板中允许使用多个类型参数。但在template定义部分的 每个模板形参前必须有关键字class。 6
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有