通过本文主要向大家介绍了c++任意进制转换,c++按任意键继续,c++请按任意键继续,c++指针详解,c++编程实例详解等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com
能够接受任意多个参数的函数,可以利用重载来实现。这种函数的执行过程类似于递归调用,所以必须要有递归终止条件。
#include <iostream> #include <bitset> void print() {} // 递归终止条件。这是必需的。 template<typename Type, typename... Types> void print(const Type& arg, const Types&... args) { std::cout << arg << std::endl; print(args...); } int main() { print(1, 3.1415, "Hello, world!", 1.618, true, std::bitset<16>(377), 40); return 0; }</div>
执行后的结果如下:
1 3.1415 Hello, world! 1.618 1 0000000101111001 40</div>
以上就是小编为大家带来的C++中可以接受任意多个参数的函数定义方法(详解)全部内容了,希望大家多多支持~
</div>