65,210
社区成员
发帖
与我相关
我的任务
分享
template <class T>
void printarg(T t)
{
cout << t << endl;
}
template <class ...Args>
void expand(Args ... args)
{
cout<<args<<endl;
}
int _tmain(int argc, _TCHAR* argv[])
{
printarg(3); //OK
expand(4); //error
return 0;
}

template <typename... T>
void Shell(T... t)
{
return;
}
template<typename T>
T print(T t)
{
cout<<t<<endl;
return t;
}
template <typename ...Args>
void print(Args ... args)
{
Shell(print(args)...);
}
template <class ...Args>
void expand(Args ... args)
{
cout<<args<<endl;
}
template <typename... T>
void Shell(T... t)
{
return;
}
template<typename T>
T print(T t)
{
cout<<args<<endl;
return args;
}
template <typename ...Args>
void print(Args ... args)
{
Shell(print(args)...);
}
#include <iostream>
#include <utility>
using namespace std;
void print()
{
}
template <typename Arg1>
void print(Arg1&& arg1)
{
std::cout << arg1 << std::endl;
}
//多于1个参数,形式上要递归(其实不是递归)
template <typename Arg1,typename... Args>
void print(Arg1&& arg1,Args&&...args)
{
std::cout << arg1 << ",";
print(std::forward<Args>(args)...);
}
int main()
{
print();
print(67.8);
print("hello", 5, std::string("go go go"));
return 0;
}

template <typename Arg1,typename... Args>
void expand(Arg1 arg1,Args... args)
{
cout << arg1;
expand(args...);
}
template <typename Arg1>
void expand(Arg1 arg1)
{
cout << arg1 << endl;
}
int main()
{
expand(1);
expand(1,2,3);
expand(1,2,3,4,5,6,7,8,9,10,"fuck vs2012",1.0f,1.0,"and fuck vs2013");
return 0;
}