Q: FunktionPointerArray in Singleton I try to implement an array of function pointers in an singleton owning a thread.
In the thread function I get an error, telling me that a member has to be relative to an object. More in the commentline...
Header:
typedef struct{
  int action;
  HWND handle;
}JOB;

class Class{
public:
  enum Action { 1,2 };

private:
  JOB    m_currentJob;
  queue<JOB> Jobs;

  static DWORD WINAPI ThreadFunction(LPVOID lpParam);

  void (Class::*ftnptr[2])(JOB Job);
  void Class::ftn1(JOB Job);
  void Class::ftn2(JOB Job);

// Singleton pattern
public:
  static Class*  getInstance(){
    if(sInstance == NULL)
      sInstance = new Class();
    return sInstance;
  }
private:
  Class(void);
  ~Class(void);
  static Class*  sInstance;
};

Body:
#include "Class.h"

Class* Class::sInstance = NULL;

Class::Class(){
  this->ftnptr[0] = &Class::ftn1;
  this->ftnptr[1] = &Class::ftn2;
}

DWORD WINAPI Class::AutoplayerThreadFunction(LPVOID lpParam)
{  
  Class *pParent = static_cast<Class*>(lpParam);

  while(true){
   (pParent->*ftnptr[pParent->m_currentJob.action])(pParent->m_currentJob);
   /* The line above causes the compiler error. Curious to me is that 
    * neither "pParent->m_currentJob" nor "pParent->m_currentJob" cause 
    * any problems, although they are members too like the ftnptr array.
    */
  }
}

void Class::ftn1(JOB Job){}
void Class::ftn2(JOB Job){}

A call via getInstance from the SingletonPattern doesnt make it any better.
Any suggestions?

A: ftnptr is a member of Class. However, you access it directly. That is, pParent->*ftnptr[...] means "access the member of pParent designated by the pointer ftnptr[...]", but it doesn't imply that ftnptr too is a member of pParent.
The correct code is (pParent->*(pParent->ftnptr[...]))(...). But I would recommend extracting the array index expression from that:
auto fnptr = pParent->ftnptr[...];
(pParent->*fnptr)(...);


A: I think it might be how you declare your array of pointer-to-member-functions. (Edit: This wasn't what was wrong. I'm keeping this answer up anyway, because typedefs for function pointers can really make code cleaner, so I think this is good advice.)
Try using a typedef:
typedef void (Class::*ftnptr)(JOB Job);
ftnptr[2] fn_ptrs;

Then use it like so:
Class::Class(){
  this->fn_ptrs[0] = &Class::ftn1;
  this->fn_ptrs[1] = &Class::ftn2;
}

DWORD WINAPI Class::AutoplayerThreadFunction(LPVOID lpParam)
{  
  Class *pParent = static_cast<Class*>(lpParam);

  while(true){
   (pParent->*(pParent->fn_ptrs[pParent->m_currentJob.action]))(pParent->m_currentJob);
   /* The line above causes the compiler error. Curious to me is that 
    * neither "pParent->m_currentJob" nor "pParent->m_currentJob" cause 
    * any problems, although they are members too like the ftnptr array.
    */
  }
}

