Calling a variadic function with an unknown number of parameters

前端 未结 5 1432
长情又很酷
长情又很酷 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:32

    When I've need to do something like this, I got it to work with a "switch-fan".

    switch( n ){
    case 1:  foo(0);     break;
    case 2:  foo(0,0);   break;
    case 3:  foo(0,0,0); break;
    }
    

提交回复
热议问题