c++ 可变参数模板
2024-10-19 05:29:25
可变参数模板,自己尝试了个例子,如下:
// variadicTemplates.cpp : 定义控制台应用程序的入口点。
// #include "stdafx.h"
#include "stdio.h"
#include "iostream"
#include "string" using namespace std; template <class... T>
void fun(T... p)
{
cout << sizeof...(p) << endl;
} template <class T>
void fun_print(T t)
{
cout << t << endl;
} template <class T, class ...args>
void fun_print(T head, args... res)
{
cout << head << endl;
fun_print(res...);
} template < typename T >
T fun_sum(T t)
{
return t;
}
template<typename T, typename ...types>
T fun_sum(T head, types ... res)
{
return head + fun_sum(res...);
} int _tmain(int argc, _TCHAR* argv[])
{
fun(, , , , );
fun(1.1, "", );
fun(true, 'a');
fun_print(, true, , 4.9, "");
cout << fun_sum(, , , ) << endl; getchar();
return ;
}
最新文章
- C# 设置word文档页面大小
- Spring任务调度之Quartz
- BZOJ2933: [Poi1999]地图
- WinForm------TreeList修改节点图标和按钮样式
- UILabel 的属性(用法)方法
- 那些年不错的Android开源项目
- Oracle Flashback Technologies - 闪回查询
- POJ1011 (DFS+剪枝)
- SSDT Hook
- 实用lsof常用命令行
- cvc-complex-type.2.4.c: The matching wildcard...
- python 使用 PIL 和 matplotlib 获取图片像素点处理之后再写入
- case when 和 decode 的比较分析
- Android UI(三)SlidingMenu实现滑动菜单(详细 官方)
- canvas.drawImage()方法详解
- python ftp文件夹文件递归上传推送
- MP实战系列(十八)之XML文件热加载
- 【BZOJ-2329&;2209】括号修复&;括号序列 Splay
- ios 加密解密工具类字符判断等
- C#可选参数、命名参数、参数数组