C++ 函数模板示例 2 (配合decltype)

#include "stdafx.h"
#include 
#include 
#include 
#include 

using std::cout;
using std::cin;
using std::endl;
using std::setw;

template 
auto product(T1 v1[], T2 v2[], size_t count) -> decltype(v1[0]*v2[0])
{
	decltype(v1[0]*v2[0]) sum(0);
	for(size_t i=0;i
上面代码的运行结果是:

C++ 函数模板示例 2 (配合decltype)_第1张图片




C++ 函数模板示例 2 (配合decltype)_第2张图片



更多完整的示例,可以参见《Visual C++ 2012入门经典》一书的212页,6.8节:使用函数的示例。





你可能感兴趣的:(VC++学习笔记)