Passing Variable Number of Arguments with different type - C++

后端 未结 6 827
闹比i
闹比i 2020-11-30 09:33

I am coding in C++ and have a few questions regarding the ellipsis:

  1. Is it possible to pass in class or class pointer into the ellipsis?

  2. Basi

6条回答
  •  情歌与酒
    2020-11-30 09:54

    You should consider that using variadic functions (C-style) is a dangerous flaw. If the objects passed to the function mismatch the type awaited, or if you don't put the exact number of parameters awaited, then you basically have a violent crash at runtime.

    In Bjarne Stroustrup C++ In Depth Series - C++ Coding Standards - 101 Rules, Guidelines, And Best Practices by Herb Sutter and Andrei Alexandrescu, chapter 98: Don't use varargs (ellipsis)

    I deeply subscribe to @tenfour's proposal:

    • use an std::vector that contains all your parameters.

提交回复
热议问题