Calling a variadic function with an unknown number of parameters

前端 未结 5 1471
长情又很酷
长情又很酷 2021-01-14 15:14

Say I have a function that takes a variable number of parameters: I want to call this function from somewhere else, building the list of parameters, but without knowing in a

5条回答
  •  独厮守ぢ
    2021-01-14 15:29

    If a special value cannot be reserved to indicate the end of the list, pass 2 arguments for each parameter. Tad wasteful but does allow code to be sequentially automatically generated without value restrictions.

    foo(0);
    foo(1, Params1, 0);
    foo(1, Params1, 1, Params2, 0);
    foo(1, Params1, 1, Params2, 1, Params3, 0);
    

提交回复
热议问题