- #include<iostream>
- using namespace std;
- int add(int a,int b,...)
- {
- return a+b;
- }
- template<typename T,typename...>
- class A
- {
- private:
- T data;
- public:
- A():data(0){}
- A(T d):data(d){}
- ~A(){}
- public:
- void dis()
- {
- cout<<data<<endl;
- }
- };
- void tprintf(const char* format)
- {
- cout<<format;
- return;
- }
- template<typename T,typename...Args>
- void tprintf(const char* format,T t,Args... args)
- {
- for(;*format!='\\0';format++)
- {
- if(*format=='%'){
- cout<<t;
- tprintf(format+1,args...);
- return;
- }
- cout<<*format;
- }
- return;
- }
- int main()
- {
- cout<<add(1,2)<<endl;
- cout<<add(1,2,3,4)<<endl;
- A<int> obj1(2);
- A<int,char> obj2(3);
- obj1.dis();
- obj2.dis();
- tprintf("% world!% \\n","hello","123");
- return 0;
- }
- //该片段来自于http://www.codesnippet.cn/detail/0109201615008.html
来源: http://www.codesnippet.cn/detail/0109201615008.html