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

后端 未结 6 836
闹比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 10:02

    If class instance (or pointer) is used always, it is better to use fixed parameter, which is passed before variable parameters list, like format in printf. Regarding ... parameters, they may have any type (including class instance or pointer), and their amount and types depend on some convention between a caller and called function. For example, for printf, such convention is defined by format string. You need to define such "communication protocol", which allows to use variable arguments list. Of course, this is not safe.

提交回复
热议问题