Reason why not to have a DELETE macro for C++

前端 未结 12 1142
臣服心动
臣服心动 2020-11-29 07:01

Are there any good reasons (except \"macros are evil\", maybe) NOT to use the following macros ?

#define DELETE( ptr ) \\
i         


        
12条回答
  •  感情败类
    2020-11-29 07:11

    1. deleting a null pointer does nothing, so no need to check whether the pointer is null before deletion. Nullifying the deleted pointer might still be needed (but not in every case).

    2. Macros should be avoided as much as possible, because they are hard to debug, maintain, introduce possible side effects, they are not part of namespaces, etc.

    3. deleting a pointer that was not dynamically allocated with new will still be a problem...

提交回复
热议问题