namespace Stuff
{
class Sprite
{
};
class Circle : Stuff::Sprite
{
};
}
Will this work, or will this look for Stuff::Stuff::Sprite?
edit: forgot some semicolons.
edit 2: I’m accepting @Omnifarious’ answer because once he edited it with @Vlad’s help, it was the most complete answer. thanks also to @Vlad.
It will work if you put in the
;after the class definitions. But it will not work in quite the way you expect. First, it tries to figure out what namespace you’re talking about. First it will looks for::Stuff::Stuff, and when it doesn’t find it, it then looks for the namespace::Stuff. It finds that namespace, so it then looks in that namespace forSpriteand finds your class.If you have an unanchored namespace, it looks for that namespace path in the current namespace, then in the enclosing namespace, then in the enclosing enclosing namespace… etc… until it gets to the top level namespace.
See this question of mine:
In my opinion, people ought to be a lot more careful than they are about referring to namespaces. Hardly anybody ever uses a root anchored namespace specification, even when they should be because they really do mean a specific absolute namespace and not a name relative to the current namespace.
Here are a couple of interesting cases: