#include "X:\Work\Share\CCode\CPlatform\Base\global_c_all.h"
using namespace lf;
using namespace std;
//递归终止函数
void Print()
{
_cout << _t("\n");
}
template <typename T, typename ...Args>
void Print(T first, Args... args)
{
_cout << first;
Print(args...);
}
void main()
{
int pi = 3.14;
Print("pi=", pi,"\t_Math::_e=", _Math::_e);
Print("a=", 10, _t("\tb="), 3.14,_t("\t水果:"), lf::水果("苹果",200,"圆形"));
}
输出:
#include "X:\Work\Share\CCode\CPlatform\Base\global_c_all.h"
using namespace lf;
using namespace std;
//递归终止函数
void Print()
{
_cout << _t("\n");
}
template <typename T, typename ...Args>
void Print(T first, Args... args)
{
std::cout << typeid(first).name() << "\n";
Print(args...);
}
void main()
{
int pi = 3.14;
Print("pi=", pi,"\t_Math::_e=", _Math::_e);
}
#include <iostream>
using namespace std;
// 定义一个函数模板,接收任意类型的参数包并打印每个参数值
template<typename T>
void printArgs(T arg) {
cout << "Arg value: " << arg << endl;
}
// 递归地展开参数包
template<typename... Args>
void expandPack(Args&&... args) {
// 将args作为单个参数传入printArgs函数进行处理
(printArgs(forward<Args>(args)), ...);
}
int main() {
int a = 10;
double b = 3.14;
string c = "Hello";
// 调用expandPack函数展开参数包
expandPack(a, b, c);
return 0;
}