Variable number of arguments in C++?

后端 未结 17 1762
-上瘾入骨i
-上瘾入骨i 2020-11-21 23:13

How can I write a function that accepts a variable number of arguments? Is this possible, how?

17条回答
  •  离开以前
    2020-11-21 23:31

    If you know the range of number of arguments that will be provided, you can always use some function overloading, like

    f(int a)
        {int res=a; return res;}
    f(int a, int b)
        {int res=a+b; return res;}
    

    and so on...

提交回复
热议问题