function pointer table and compile error
I have a small program which need to define a function pointer table, unfortunately, this code will be C code which need to be compiled with other C++ code (gcc on linux).
Please help me out.
I get the error like this:
gcc -c -g funct.cpp
In file included from funct.cpp:5:
funct.hpp:40: excess elements in aggregate initializer
funct.hpp:40: excess elements in aggregate initializer
funct.hpp:40: excess elements in aggregate initializer
funct.cpp: In function `int main(int, char**)':
funct.cpp:130: cannot resolve overloaded function `funcptr' based on conversion
to type `void*'
Here it is the snapshot of the code "funct.hpp"
void PrintHello1(void *params);
void PrintHello2(void *params);
void PrintHello3(void *params);
char *messages[NUM_THREADS];
struct thread_data
{
int thread_id;
int sum;
char *message;
};
struct thread_data thread_data_array[NUM_THREADS];
typedef void Func(void *);
struct PrintHi {
int msg;
Func funcptr;
};
struct PrintHi PrintHiTable[] = {
{ MSG1, PrintHello1 },
{ MSG2, PrintHello2 },
{ MSG3, PrintHello3 }
}; // funct.hpp code line 40
Another file funct.cpp
for(t=0;t<NUM_THREADS;t++) {
sum = sum + t;
thread_data_array[t].thread_id = t;
thread_data_array[t].sum = sum;
thread_data_array[t].message = messages[t];
printf("Creating thread %d\n", t);
rc = pthread_create(&threads[t], NULL, (void *)PrintHiTable[t].funcptr, (void *)&thread_data_array[t]); // funct.cpp code line 130
|