0

I have a struct within a class which contains a list of commands and the function mapped to each command. I'm trying to then call a invoke the function pointer within another function in that class, However, the compiler keeps returning a called object type 'void (Csac::*)(char *, unsigned int, void *)' is not a function or function pointer error.

Here is a sample code

class Atom
{
  public:

    struct cmds_t
    {
        char cmd[20];
        void (Atom::* func)(char * data, unsigned int length, void * _atom);
    };

    void call_ptr_func(int i, char * data, unsigned int length, void * _atom);

  private:
    cmds_t atom_cmds[16] = {NULL};  

}

void atom::call_ptr_func(int i, char * data, unsigned int length, void * _atom) 
{   
    (this->atom_cmds[i].func)(data, length, NULL); 
}

void Atom::initialise_cmds()
{
  atom_cmds[0] = {.cmd = "!^",  .func = &Atom::funcA};
  atom_cmds[1] = {.cmd = "!TA", .func = &Atom::funcB};
   ...........
  atom_cmds[15] = {.cmd = "!S", .func = NULL};
}

void  Atom::funcA(char *data, unsigned int bytes, void * _atom)
{
  /// Stuff happens
}

Unfortunately, I can only compile with c++14 and I'm unable to use std::invoke. What am I doing wrong here?

Jadzn
  • 11
  • 2

0 Answers0