December 2001
Intermediate to advanced
304 pages
6h 25m
English
Difficulty: 4
Preprocessor macros are part of C++'s heritage from C. This Item considers whether they are still relevant in the modern C++ scheme of things.
With flexible features such as overloading and type-safe templates available, why would a C++ programmer ever write a preprocessor directive like “#define”?
C++ features often, but not always, cancel out the need for using #define. For example, “const int c = 42;” is superior to “#define c 42” because it provides type safety, and avoids accidental preprocessor edits, among other reasons.
There are, however, still a few good reasons to write #define.
Read now
Unlock full access