On 13 Apr 2004 10:50:58 -0700 in comp.lang.c++,
a.****@iu-bremen.de
(Aakash Jain) wrote,
Can someone explain me the difference between the following C++ macro
and the function MAX:
#define MAX(a, b) (((a) > (b)) ? (a) : (b))
template <class T>
const T& MAX(const T& a, const T& b)
{
return (a > b ? a : b);
}
1. Pass MAX as a function argument to another function, e.g.
// make all numbers non-negative
std::transform(v.begin(), v.end(), v.begin(),
std::bind2nd(MAX<double>, 0.0));
2. Define a class with a private member function that happens
to be named MAX.
3. Try to solve the problems with (1) and (2) by making MAX
a member of a namespace.