I was testing the name lookup rules for C++. I've got a simple program having 3 files:
$cat testns01.h
struct S{
static int f(){return 1;}
};
$cat testns02.h
namespace S{
static int f(){return 2;}
}
$cat testns3.cpp
#include "testns02.h" // namespace
#include "testns01.h" // struct
#include<stdio.h>
int main()
{
int i = S::f();
printf("%d\n",i);
return 0;
}
If I compile and run, I get:
$g++ testns3.cpp && ./a.out
1
OK, I have 3 questions:
- name "S" duplication between class name and namespace doesn't conflict?
- When both has name "S", seems "struct S" has higher priority
If I comment the line of #include "testns01.h", the program will print 2, still OK. So my third question is:
- Does the c++ standard talk about how name lookup resolves duplicated name duplication?