利用va_list向拥有可变参数函数传入可变的参数
#include <iostream> #include <cstdarg> using namespace std; typedef int (*PCALLBACK)(int nCount,va_list vlist); int addInt(int nCount,va_list vlist) { int sum = 0; for (int i=0;i<nCount;i++) { sum+=va_arg(vlist,int); } return sum; } void func(PCALLBACK pCall,int nCount,...) { va_list valist; va_start(valist,nCount); cout<<pCall(nCount,valist)<<endl; va_end(valist); } int main() { func((PCALLBACK)addInt,4,1,2,9,-4); return 0; }