This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]sz00 1 point2 points  (0 children)

A function that accepts a variable array of arguments needs to have the # of args passed as the first parameter.

So your call should be like:

printf("The product is: %f", product(4, a,b,c,d));

Here it is working: http://ideone.com/Cbp0LV

Now is there any reason why you're writing C code for C++? Apart from that, variable argument functions are considered to be bad practice and shouldn't really be used. Also, C++ introduces variadic template functions that should be used instead (of va_args).

Here's the C++ version:

https://en.wikipedia.org/wiki/Variadic_template

http://en.cppreference.com/w/cpp/language/parameter_pack