I am trying to get a list (yes I know it's an array) of things out of a callback function. I seem to be going round in circles, I'm assuming it's something silly that I haven't noticed, or I'm going about it all wrong.
class.cpp
client_list* client::get_list(sqlite3* db) {
char* err;
sqlite3_exec(db, "SELECT client_id FROM clients", list_callback, 0, &err);
if ( err ) {
fprintf(stderr, "There was a problem with the query: %s\n", err);
sqlite3_free(err);
return new client_list{0,0};
}
return &list;
}
int client::list_callback(void *NotUsed, int argc, char **argv, char **azColName) {
list.clients = new client[argc];
for (int i = 0; i<argc; i++) {
//We are only requesting one column, it can therefor be assumed that
//the value will be in the first position in the row.
list.clients[i] = new client(static_cast<int>(*argv[i]));
}
return 0;
}
class.h
class client;
typedef struct {
client** clients;
int length;
} client_list;
class client {
public:
char* name;
client();
client(char* name);
client(int client_id);
int id();
static client_list* get_list(sqlite3* db);
~client();
private:
int client_id;
static client_list list;
static int list_callback(void *NotUsed, int argc, char **argv, char **azColName);
};
output
undefined reference to `client::list'