title: Alternative to c++ static virtual methods
body: <p>In C++ is not possible to declare a static virtual function, neither cast a non-static function to a C style function pointer.</p>
  
  <p>Now, I have a plain ol' C SDK that uses function pointers heavily. </p>
  
  <p>I have to fill a structure with several function pointers.  I was planning to use an abstract class with a bunch of static pure virtual methods, and redefine them in derived classes and fill the structure with them. It wasn't until then that I realized that static virtual are not allowed in C++.</p>
  
  <p>Also this C SDKs function signature doesn't have a userData param.</p>
  
  <p>Is there any good alternative? The best I can think of is defining some pure virtual methods GetFuncA(), GetFuncB(),... and some static members FuncA()/FuncB() in each derived class, which would be returned by the GetFuncX(). Then a function in the abstract class would call those functions to get the pointers and fill the structure.</p>
  
  <p><strong>Edit</strong>
  Answering to John Dibling, it would be great to be able to do this:</p>
  
  <pre><code>class Base
  {
      FillPointers() { myStruct.funA = myFunA; myStruct.funB = myFunB; ...}
  private:
      CStruct myStruct;
      static virtual myFunA(...) = 0;
      static virtual myFunB(...) = 0;
  };
  
  class Derived1 : public Base
  {
      Derived1() {  FillPointers();  }
      static virtual myFunA(...) {...};
      static virtual myFunB(...) {...};
  };
  
  class Derived2 : public Base
  {
      Derived2() {  FillPointers();  }
      static virtual myFunA(...) {...};
      static virtual myFunB(...) {...};
  };
  
  int main()
  {
      Derived1 d1;
      Derived2 d2;
      // Now I have two objects with different functionality
  }
  </code></pre>