search

Home  >  Q&A  >  body text

C++ 如何实现 spreading array 的参数?

形参 (parameters) 类似

f(a, ...)

的形式。

那么函数体应该如何实现?

PHP中文网PHP中文网2803 days ago619

reply all(2)I'll reply

  • 怪我咯

    怪我咯2017-04-17 13:11:33

    Since the question is about C++, then

    template<typename ...T>
    void f(int a, T... t);
    

    Of course that is the case, and then you can access every value in t through simple template metaprogramming techniques.

    reply
    0
  • 大家讲道理

    大家讲道理2017-04-17 13:11:33

    The description of the problem is not very clear. I assume you want to know how to obtain the ... parameter in C language and see how to use va_list, va_start and the like.
    http://en.cppreference.com/w/cpp/utility/variadic/va_start
    http://en.cppreference.com/w/cpp/utility/variadic/va_list

    reply
    0
  • Cancelreply