title: C++ type of enclosing class in static member function
body: <p>I assume this is outright impossible, but what if. Is it possible to somehow get type of enclosing class in a static member function, in any version of C++?</p>
  
  <pre><code>class Impossible {
  public:
      static void Fun()
      {
          typedef Impossible EnclosingClass;
  
          // now do something with EnclosingClass ...
      }
  }
  </code></pre>
  
  <p>Is there a way to get the type of the enclosing class (<code>Impossible</code> in this case) without writing the name of the class in the function?</p>
  
  <p>The reason why I'd like to do that is to avoid repeating the class name in the function. It could easily lead to a hard to find copy-paste bug, if something like this happened:</p>
  
  <pre><code>class SomeOther { // another class, with the same interface as Impossible
  public:
      static void Fun()
      {
          typedef Impossible EnclosingClass;
          // whoops, copy-pasted, forgot to change "Impossible" to "SomeOther"
  
          // now do something with EnclosingClass ...
      }
  }
  </code></pre>
  
  <p>Is there a good way to prevent this kind of thing happening? I could imagine touching something that was declared private in the enclosing class, but that would be forcing me to write extra code (as my current design doesn't contain any inherent private members, all is public).</p>