templates like macros?
Can templates do more than just create classes and functions for multiple data types? can they do more generalized replacements like macros, and are there any template conditionals like the preprocessor #ifdef?
I''m not exactly sure if this is what you''re asking, but templates can do things like type switching, which can sort of act like preprocessor conditionals. However, the syntax for doing so is often less elegant. On the other hand, you get better type safety. This also comes with the caveat that there already different compiler/C++ features that can be used to replace preprocessor conditionals depending on the circumstances. For example, in most cases I prefer normal if statements on constants to #ifdef.
If you want a more specific explanation, try giving a specific example.
If you want a more specific explanation, try giving a specific example.
Look up template metaprogramming. With a compiler that supports templates properly (*cough*VC6*cough*), they can be amazing.
edit: Two seconds late.. I must be getting old.
[edited by - psykr on January 24, 2004 1:52:57 PM]
edit: Two seconds late.. I must be getting old.
[edited by - psykr on January 24, 2004 1:52:57 PM]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement