Quick Q: Why use C varargs when you have initializer_lists and variadic templates? -- StackOverflow

Quick A: No reason, varargs are type-unsafe and entirely superseded by C++11 features (unless you need C compatibility).

Why use variadic arguments now when initializer lists are available?

I've been wondering what are the advantages of variadic arguments over initializer lists. Both offer the same ability -- to pass indefinite number of arguments to a function.

 

What I personally think is initializer lists are a little more elegant. Syntax is less awkward.

Also, it appears that initializer lists have significantly better performance as the number of arguments grows.

 

So what am I missing, besides the possibility to use use variadic arguments in C as well?

Add a Comment

Comments are closed.

Comments (1)

0 0

Jeff Schwab said on Mar 18, 2013 04:47 PM:

Why do you feel that you are missing something? The addition of new features that mostly obsolete old features does not necessitate, nor even permit, the immediate removal of old features from the language.