- 论坛徽章:
- 2
|
本帖最后由 OwnWaterloo 于 2011-10-11 22:48 编辑
回复 38# 幻の上帝
老师是尊称……
从实践上来说:
exceptional c++ Item 20. Class Mechanics 11. Avoid reserved names.
Yes, popular books like Design Patterns (Gamma95) do use leading underscores in variable names, but don't do it.
The standard reserves some leading-underscore identifiers for the implementation,
and the rules are hard enough to remember for you and for compiler writers
that you may as well avoid leading underscores entirely[1].
Instead, my own preference is to follow the convention of designating member variable names with a trailing underscore.
[1] For example, names with leading underscores are technically reserved only for nonmember names,
so some would argue that this isn't a problem and that class member names with leading underscores are fine.
That's not entirely true in practice,
because some implementations #define macros with leading-underscore names,
and macros don't respect scope.
They'll tromp on your member names as easily as they'll tromp on your nonmember names.
It's easier just to leave all leading underscores for implementers and avoid the possible hassles.
"some implementations #define macros with leading-underscore names"里的"leading-underscore"是指 _X, y__ 还是 _z ?
_X, y__ 应该是被保留作任意使用,不使用它们应该毫无异议。
所以我猜作者指的是 _z 。
也许作者是真的遇见过这样一种C++实现: 库的作者没能记住完整的规则, 所以使用 _z 作为宏名。 |
|