1. 为什么要用anonymous namespace?

6.15 — Unnamed and inline namespaces

This might make unnamed namespaces seem useless. But the other effect of unnamed namespaces is that all identifiers inside an unnamed namespace are treated as if they had internal linkage, which means that the content of an unnamed namespace can’t be seen outside of the file in which the unnamed namespace is defined.

For functions, this is effectively the same as defining all functions in the unnamed namespace as static functions. The following program is effectively identical to the one above:

// 非法代码
static class sample_class { /* class body / };
static struct sample_struct { /
struct body */ };

// 合法代码
namespace
{
class sample_class { /* class body */ };
struct s
}