How to call C++ member function in julia?

by using ccall and function address, the global function in C++ can be called. But how about member function? Calling member function needs the function pointer and object reference both, it seems that ccall cannot make it in julia.

I don’t know if you know these packages, but these solve your problem: Cxx.jl and CxxWrap.jl.

1 Like

yeap, CxxWrap.jl can work. But it just wraps the class in C++ and then exposes it to julia and later all works in julia. But my condition is: the object still in C++ side, may I send a order to ask the object to run its member functions(there are dozens of similar functions, I have to deal with them in julia side due to its excellent sytanx). Since my codes runs from C++, inside I jl_init() the julia and deal sth, according to the results, the inside julia need call back the C++ side member function.

This can be done in CxxWrap, using the method function on the C++ side. This generates functions that can be called from Julia, with the C++ object as first argument.

Where is the C++ object you mentioned above created? What I need is created in C++ side. If yes, how to send it to julia side, by a void pointer?

Yes, objects are created on the C++ side and passed to Julia in a struct that only contains a void pointer to the object.