Scope resolution operator
c++, g++, scope
Solution
This code is not valid.
It was a bug in g++ that it accepted the code. See "g++ does not treat injected class name correctly." The bug was resolved as fixed in 2009, so it should be fixed in any recent version of g++.
Problem
I accidentally happened to find this in one of the source codes I was looking at. So, I'm giving a similar smaller example here. In the file test.h: ``` #include<iostream> class test{ int i; public: test(){} //More functions here }; ``` In the file test.cpp: ``` #include "test.h" int main() { test test1; test::test test2; test::test::test test3; return 0; } ``` First of all, is there a reason to declare `test2` that way? Secondly, this code compiles just fine in g++ version 4.4.3 and lower versions. Is there something in the C++ standard, saying, scope resolution operators are ignored when there is no need to resolve scope?