How can I extend the following code for MAX(a, b, c), MAX(a, b, c, d) etc without writing out a new function?
Code:double MAX(double M, double N)
{
if (M > N){return M;}
else{return N;}
}
Printable View
How can I extend the following code for MAX(a, b, c), MAX(a, b, c, d) etc without writing out a new function?
Code:double MAX(double M, double N)
{
if (M > N){return M;}
else{return N;}
}
max_element() from <algorithm> returns an iterator to the maximum element in a sequence.
Edit: If you insist on writing your own implementation, you probably want to express the input as a sequence in the same way that the Standard Library does, so you don't have to deal with variadic functions.
i don't understand what you mean
http://www.cppreference.com/cppalgor...x_element.html
A variadic function is one that can take a variable number of arguments. For your purposes, you probably don't want to create one of those. Look at the example in the link above and then create a function that works the same way that max_element() does, or just use max_element(). max_element() is NOT variadic - it takes just two arguments (or three if you use the generalized version).
Thanks