0

I am preparing a short presentation on templates for work and am using isocpp.org as a starting point for the content. However, I have come across an interesting paragraph:

A note to the experts: I have obviously made several simplifications above. This was intentional so please don’t complain too loudly. If you know the difference between a .cpp file and a compilation unit, the difference between a class template and a template class, and the fact that templates really aren’t just glorified macros, then don’t complain: this particular question/answer wasn’t aimed at you to begin with. I simplified things so newbies would “get it,” even if doing so offends some experts.

There are a few things that confuse me, one of which is that "templates aren't just glorified macros". I mean obviously macros are an enormously simple mechanism, just a find-and-replace type of deal, and templates obviously require more care when replacing the type arguments with the actual types given by the programmer etc. so the actual logic that goes into a template expansion is much more complicated.

But I was under the impression that templates are indications for the compiler to start from the above Node class, and a Node<int> node; declaration somewhere, and then completely generate the C++ code for the class Node__int (or a similar mangled name) and the just compile it like any other class. This... does sound similar to a macro, so to me it seems like a fair comparison. So what is the difference?

Rares Dima
  • 1,502
  • 12
  • 35

0 Answers0