phate89
phate89

Reputation: 137

Error C2065 with function pointer to static member class

I'm trying to change an existing code of a static const struct in my header class used as a base for my db creation. The current code is

//database.h

#define VIDEODB_TYPE_INT 1
const struct DBHeaders
{
  std::string name;
  std::string dbType;
  int type;
} DBHeadersTable1[] = 
{
  { "idRow", "INTEGER PRIMARY KEY", VIDEODB_TYPE_INT},
  { "value", "INTEGER", VIDEODB_TYPE_INT}
};

const struct DBHeaders DBHeadersTable2[] = 
{
  { "idRow", "INTEGER PRIMARY KEY", VIDEODB_TYPE_INT},
  { "value", "INTEGER", VIDEODB_TYPE_INT}
};

class CDatabase
{
public:
  void getDatabaseInteger(DatabaseRow& details);
  void get(int column, DBHeaders headers, DatabaseRow& details)
  {
    if (headers[i].type == VIDEODB_TYPE_INT)
      getDatabaseInteger(details);
  }
  //other functions
}

But this method isn't great anymore because now we have fields that needs changes to be used. So instead of giving a number that represents the function I want to insert directly a pointer to the function allowing a lot more flexibility. This is my new code

//database.h

typedef void (*getFunctionType)(DatabaseRow&);
const struct DBHeaders
{
  std::string name;
  std::string dbType;
  getFunctionType getFunction;
} DBHeadersTable1[] = 
{
  { "idRow", "INTEGER PRIMARY KEY", &(CDatabase::getDatabaseInteger)},
  { "value", "INTEGER", &(CDatabase::getDatabaseInteger)}
};

const struct DBHeaders DBHeadersTable2[] = 
{
  { "idRow", "INTEGER PRIMARY KEY", &(CDatabase::getDatabaseInteger)},
  { "value", "INTEGER", &(CDatabase::getDatabaseInteger)}
};

class CDatabase
{
public:
  static void getDatabaseInteger(DatabaseRow& details);

  //other functions
}

The idea is that to have a defined const with my rows and a pointer to the function the code have to use to parse the column. The error i get is: https://msdn.microsoft.com/en-us/library/ewcf0002.aspx at line

  { "idRow", "INTEGER PRIMARY KEY", &(CDatabase::getDatabaseInteger)},

And between parenthesis of the error i don't have "database.h" but another file... Is it possible to point a static function in this way? Am I doing something wrong?

Upvotes: 0

Views: 186

Answers (1)

Sam Varshavchik
Sam Varshavchik

Reputation: 118320

Based on the code you posted, it looks to me like you need to declare the class:

class CDatabase
{
public:
  static void getDatabaseInteger(DatabaseRow& details);

  //other functions
};

before all the arrays that reference the CDatabase::getDatabaseInteger() method in the same header file. Looks like in your header file you are referencing the static function before you actually declare it. Move this declaration to the beginning of the file.

Upvotes: 1

Related Questions