We develop some project in plain C
(C99). But, we have one library as source codes (math library) in C++
. We need this library so I would like to a
There is a way to create a "hack" that allows you to call member functions of some objects directly.
The first thing you have to do is to create an extern "C"
factory function, which returns a pointer (as void*
) to the object.
The second thing you need is the mangled name of the member function.
Then you can call the function using the mangled name, and passing the pointer returned from the factory function as the first argument.
Caveats:
This is not something I recommend, quite the opposite in fact. I strongly advise against doing something like outlined in this answer. It's unsupported and probably undefined behavior and may break in weird and unpredictable ways.