In other words, names that begin with a leading underscore and that are not
in the global namespace are available as names for the program to use. And
since the names of member variables are names in the scope of the class that
defines them - they are not names in the global namespace itself. So a
program is free to use a name with a (single) leading underscore as the name
of a class member.
Not quite. As Erik Wikström says elsethread, names beginning with a
leading underscore followed by an uppercase letter are reserved for
the implementation for any use. So, Because member variables are not
in the global namespace, _Member is an illegal name for a member
variable whereas _member is not. _Global and _global are both illegal
names in the global namespace.
Also not mentioned yet, names containing a double underscore anywhere
in the name are reserved for the implementation for any use.
Nevertheless, to keep things simple it is probably a good
idea for a program not to use a name with a leading underscore anywhere -
even when it may be OK to do so.
Agreed. And the same for names containing a double underscore. I know
what the rules are and I know where to look them up to remind myself
if I forget (mainly because this question arises here every so often).
But I see no advantage in demonstrating in code how clever I am by
allowing myself to use leading underscores where they are legal. Far
simpler to just avoid leading underscores and double underscores
completely (and I don't find that restriction causes me any difficulty
at all).
Gavin Deane