On Mar 20, 7:42 am, Juha Nieminen <nos...@thanks.invalidwrote:
Fei Liu wrote:
Does this do what I want?
It's not nameless, it's anonymous (its name is hidden from you). What's
the logical outcome of this classification on the terminology then?
A "yes" or "no" answer would have been more helpful.
Yes, there is something known as "unnamed" namespaces. If you have
access to Bjarne Stroustrup's "C++ Programming Language," he does a
good job of explaining it. The basic idea of unnamed namespaces is to
keep names within the unnamed namespace local to the translation unit
(i.e. source file) in which they were declared. What is unique about
unnamed namespaces is that when you use an unnamed namespace, there is
an implied using-directive. That way you can use the names that were
declared within the namespace, inside the same translation unit.
You also asked about this syntax:
class ::A { <implementation};
My understanding is that whenever you proceed a name with "::", that
refers to the global namespace, which would be different from the
unnamed namespace. Do an experiment. Try creating a class 'A' in the
global namespace and one in an unnamed namespace. Give them different
public members or methods, so you can easily tell them apart and see
how you can use them in the same source file.
Good luck!