Possible Duplicate:
Why are redundant scope qualifications supported by the compiler, and is it legal?
I wouldn't expect this to compile but it does. Could this be a compiler bug, or does it have some correct meaning?
$ g++ -c scopes.cpp
$ cat scopes.cpp
class Log {
public:
Log() { }
static void fn() { }
};
void test() {
Log::Log::Log::Log::Log::Log::fn();
}
$ g++ --version
g++ (Ubuntu 4.4.3-4ubuntu5.1) 4.4.3
Yes, it's legal. A class's name is inserted into its own namespace, which is called the injected-class-name. From C++03 §9/2:
Note that
Log::Log
names the class constructor, which is only allowed in certain contexts, but as long as you end the chain ofLog::Log::...
with something other thanLog
(such asfn
), then it doesn't name the constructor. Specifically, §3.4.3.1/1a says: