title: How to make a debuggable file scoped (static?) class in c++?
body: <p>I define a lot of classes in my cpp files. Often with unimaginative names, such as 'Implementation'. and am worried about name collisions, as these are horrible to debug (assuming the compiler silently drops one of the definitions). However, I also want to be able to debug my program, so anonymous namespaces are not an option. So, can file-scoped (aka. translation-unit scoped) classes be defined in c++ without using namespaces? If yes, how?</p>
  
  <p><strong>File-scoping in c</strong><br>
  In c, one can create a global variable with <code>int foo;</code>, and limit the variable to file-scope using <code>static int foo;</code>. Similarly, file-scoped functions are also created with the <code>static</code> keyword, for example <code>static void bar();</code>. And structs do not define data or executable code, and thus are effectively always file-scoped.</p>
  
  <p><strong>Virtual member functions</strong><br>
  Now c++ introduced virtual member functions, which caused structs (aka. classes) to contain data and executable code. Hence structs are now globally defined. However, it is not allowed to use static to make the struct file-scoped again. I.e. <code>static struct Foo{};</code> does not compile.</p>
  
  <p><strong>Namespaces</strong><br>
  To tackle the problem of name collisions, c++ also introduced named namespaces. Those can also be used to wrap the struct, such that it becomes pseudo-file-scoped. Though this still forces you to pick a unique name (that you don't even care about) for every file. As a solution, they also introduced anonymous namespaces. Unfortunately, neither gdb nor the visual studio debugger seem to support anonymous namespaces (it is basically impossible to refer to anything inside the anonymous namespace).</p>