Templates vs. Macros

HomeOverviewHow Do I

In many ways, templates work like preprocessor macros, replacing the templated variable with the given type. However, there are many differences between a macro like this:

#define min(i, j) (((i) < (j)) ? (i) : (j))

and a template:

template<class T> T min (T i, T j) { return ((i < j) ? i : j) }

Here are some problems with the macro: