I'm trying to use a C library from my C++ project.
The C library has a function like this that I'm supposed to pass callback functions into:
void c_function(int args, const void *func){};
So my C++ code should call it like this:
int function1(int a) {return a;}
int function2(int a, int b) {return a+b;}
int main(int argc, char *argv[])
{
c_function(1, function1);
c_function(2, function2);
return 0;
}
My issue is that if I compile this calling code as C, it works fine and doesn't even have any warnings. If I compile the calling code as C++, however, it has the compile error: invalid conversion from 'int ()(int)' to 'const void', for example.
I'm not sure what I need to do to get it working in C++. I'm going to have a lot of these calls in my C++ program.
My question is: how can I make this work without changing the calling code, and why does this work in C but not C++? I thought C++ was a superset of C.