书上说,当无法列出传递函数的所有实参的类型和数目时,可用省略号指定参数表
(...)
如:void foo(...);
void foo(parm_list,...);
void foo(...)
{
//...
}
调用:foo(a,b,c);
就是不懂,把a,b,c的值传进函数里面后,用什么变量来接收???如果不能接收,(...)岂不是没意义?
还有就是不明白
int printf(const char*...);
printf("hello,&s/n",userName);
这个c的输出函数是怎么用(...)实现的.
先谢了:)
Re:
首先函数体中声明一个va_list,然后用va_start函数来获取参数列表中的参数,使用完毕后调用va_end()结束。像这段代码:
void TestFun(char* pszDest, int DestLen, const char* pszFormat, ...)
{
va_list args;
va_start(args, pszFormat);
_vsnprintf(pszDest, DestLen, pszFormat, args);
va_end(args);
}
1339


&spm=1001.2101.3001.11974&articleId=566798&d=1&t=3&u=78a3eaca32cd4fc791b79464401dc12e)

被折叠的 条评论
为什么被折叠?



