Synopsis: | Do not use the preprocessor directive #define to obtain more efficient code; instead, use inline or template methods/functions |
Language: | C++ |
Severity Level: | 9 |
Category: | Preprocessor |
Description: |
An advantage of inline or template methods/functions is that they don't have side-effects as macros have (see [PRE#003]). Another advantage is that inline or template methods/functions are type-safe. A macro "function" can be defined as a template function, as in: #define MAX(p1, p2) (((p1) > (p2)) ? (p1) : (p2)) template<class T> T& Max( const T& p1, const T& p2); |