title: Call a non-static class function from a static function
body: <p>We have a static class function in our code that houses a fair amount of code. Where this code was originally used, and still is used, no instance of the class can be created hence why it is static. The functionality of this function is now needed elsewhere in our codebase, where an instance of the class is already created.</p>
  
  <p>Without making a non-static and static version of the same function is there anyway we can create a non-static function that houses all the code that can be polled using the static function in places where no class instance can be initialized, while allowing it to be called using the actual instance elsewhere.</p>
  
  <p>For example</p>
  
  <pre><code>#include &lt;iostream&gt;
  
  class Test
  {
  public:
      Test(){};
      ~Test(){};
      void nonStaticFunc(bool calledFromStatic);
      static void staticFuncCallingNonStaticFunc();
  };
  
  void Test::nonStaticFunc(bool calledFromStatic)
  {
      std::cout &lt;&lt; "Im a non-static func that will house all the code" &lt;&lt; std::endl;
      if(calledFromStatic)
      // do blah
      else
      // do blah
  }
  
  void Test::staticFuncCallingNonStaticFunc()
  {
      std::cout &lt;&lt; "Im a static func that calls the non static func that will house all `the code" &lt;&lt; std::endl;
      nonStaticFunc(true);
  }
  
  int main(int argc, char* argv[])
  {
     // In some case this could be called as this     
     Test::staticFuncCallingNonStaticFunc();
  
     // in others it could be called as 
     Test test;
     test.nonStaticFunc(false);
  }
  </code></pre>
  
  <p>Depending on if its call statically or not the code may alter slightly within the non static function, so we cant simply use a static function at all times, because sometimes we will need access to non-static members used elsewhere in the code. Most of the code will remain identical however. Cheers</p>