Are C++ templates just a kind of glorified macros?

Posted by Gulshan on Programmers See other posts from Programmers or by Gulshan
Published on 2011-03-01T17:39:04Z Indexed on 2011/03/07 8:17 UTC
Read the original article Hit count: 414

Filed under:
|
|
|

From different comparisons among C++ templates and C#/Java generics like this one-

http://stackoverflow.com/questions/31693/what-are-the-differences-between-generics-in-c-and-java-and-templates-in-c/31929#31929

I have a got a perception that, C++ templates are implemented by some kind of preprocessing, not compiling. In other words, they are just a kind of C macros. Is this right?

Then I felt that, if C++ templates are implemented by preprocessing, dynamic linking(.dll) cannot be used. A quick google search also supports this.

And lastly, how can we use macros in C to deliver C++ templates like functionalities?

Another thing came in my mind about templates similar to some kind of preprocessor that, there can be integers passed as arguments to some templates. And it even supports kind of recursion. But the recursion is not in the assembly/machine code. So, am I wrong calling templates glorified macros? Unlike normal macros, it has some superior abilities. But isn't it a kind of preprocessing?

© Programmers or respective owner

Related posts about c++

Related posts about c