我一直在问这个问题,但是我从来没有得到一个真正好的答案; 我认为几乎所有的程序员在写第一个“ Hello World”之前都遇到过这样的短语,比如“宏不应该被使用”,“宏是邪恶的”等等,我的问题是: 为什么?有了新的 C + + 11,在这么多年之后还有真正的替代品吗?
The easy part is about macros like #pragma
, that are platform specific and compiler specific, and most of the time they have serious flaws like #pragma once
that is error prone in at least 2 important situation: same name in different paths and with some network setups and filesystems.
但是一般来说,宏和它们的替代用法怎么办呢?