Variable number of parameters in function in C++

前端 未结 8 1832
借酒劲吻你
借酒劲吻你 2020-12-07 20:32

How I can have variable number of parameters in my function in C++.

Analog in C#:

public void Foo(params int[] a) {
    for (int i = 0; i < a.Leng         


        
8条回答
  •  有刺的猬
    2020-12-07 21:20

    See Variadic functions in C, Objective-C, C++, and D

    You need to include stdarg.h and then use va_list, va_start, va_arg and va_end, as the example in the Wikipedia article shows. It's a bit more cumbersome than in Java or C#, because C and C++ have only limited built-in support for varargs.

提交回复
热议问题