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

前端 未结 12 1146
臣服心动
臣服心动 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:35

    • delete accept a NULL pointer without problem, so the tests are superfluous.
    • resetting the pointer to NULL is not always possible, so they can't be used systematically.
    • the security they bring is illusory: in my experience, most dangling pointer problems comes from pointers other than the one used to delete.

提交回复
热议问题