How to loop through a va_list if the number of arguments is unknown?

后端 未结 5 615
遇见更好的自我
遇见更好的自我 2021-02-13 14:57

How do I loop through a va_list if the number of additional arguments is unknown?

#include 
#include 

int add(int x, int y, ...         


        
5条回答
  •  清酒与你
    2021-02-13 15:54

    You probably want to do something like pass the number of arguments as the first parameter.

    E.g. see here: http://www.cplusplus.com/reference/clibrary/cstdarg/va_start/

    And more discussion here: http://www.learncpp.com/cpp-tutorial/714-ellipses-and-why-to-avoid-them/

    Variable arguments can be hazardous so if at all possible I'd try to avoid them. Passing a "vector" type which includes size and a pointer to the element array would be safer.

提交回复
热议问题