When you use a macro, the code behind it is expanded all on to the same source code line, as far as the debugger is concerned. The debugger sees MY_MACRO(), and treats that single line no matter how much code is really inside the macro.
In C++, templates can do most of the things macros can, but they work much, much more elegantly. Since they're a real part of the language, you can step in to them with the debugger, too! For example:
// Macro FIND() - ugly, buggy, and can't ever be stepped in to by debugger!
#define FIND(begin, end, value) \
{ \
for ( ; begin != end; ++begin) { \
if (*begin == value) \
break; \
} \
}
// Templated find() - works beautifully and can be debugged like a real function!
template<typename Iter, typename T>
Iter find(Iter begin, Iter end, const T& value)
{
for ( ; begin != end; ++begin) {
if (*begin == value)
return begin;
}
}
Note: find() is of course a standard library function, but I've simply written this to compare it to a macro, to demonstrate how it can be debugged. Not to mention the macro version has lots of other problems. Rule of thumb: avoid macros for writing code whenever possible!