Which disadvantages could I have if I want to use the function
foo(int num, ...)
to implement the variable number of arguments?
I do know the first disadvantage that you can only use one data type.
Is there any way else to do that?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
There are multiple ways NOT to use ellipsis notation.
Why ? Because of type safety a hazardous manipulations of the primitives (
va_start,va_arg,va_next) that you can’t really forward to another function etc…However, contrary to C, C++ provides template methods, which offer type safety and generic behavior, and this can be cumulated with overloads:
This is the current state of the art, which is generally helped by a subtle application of Preprocessor Programming (check out Boost.Preprocessor).
With the new C++0x standard, come the variadic templates, which offer the same facilities than the C variadic methods, with type safety offered (yeeha)
This also allows to define
tupleclasses much more easily 🙂