#include <stdio.h>
#include <stdarg.h>
void testit ( int i, ...)
{
va_list argptr;
va_start(argptr, i);
if ( i == 0 ) {
int n = va_arg( argptr, int );
printf( "%d/n", n );
} else {
char *s = va_arg( argptr, char* );
printf( "%s/n", s);
}
}
int main()
{
testit( 0, 0xFFFFFFFF ); // 1st problem: 0xffffffff is not an int
testit( 1, NULL ); // 2nd problem: NULL is not a char*
}
C++ 可变形参 用法示例[摘自MSDN]
最新推荐文章于 2022-08-19 13:29:51 发布