Anything like the c# params in c++?

后端 未结 4 1249
后悔当初
后悔当初 2021-02-18 19:26

That is the question.

4条回答
  •  [愿得一人]
    2021-02-18 20:02

    For unmanaged C++ with the same convenient syntax, no.

    But there is support for variable argument lists to functions in C++.

    Basically you declare a function with the last parameter being an ellipsis (...), and within the body of the function use the va_start()/va_arg() calls to parse out the supplied parameter list.

    This mechanism is not type safe, and the caller could pass anything, so you should clearly document the public interface of the function and what you expect to be passed in.

    For managed C++ code, see Reed's comments.

提交回复
热议问题