Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

The example (simple.cc) seems to give libfov instances of C++ classes… but how can a C lib accept a C++ class?

class classes INSTANCES Lib
0
Posted

The example (simple.cc) seems to give libfov instances of C++ classes… but how can a C lib accept a C++ class?

0

You’re right, you can’t pass a C++ object to a C library but you can pass a pointer to a C++ object to a C library as long as that C library does not know about the C++ class (i.e. uses void rather than a class), does not try to dereference the pointer, cast the pointer, or do anything with the data being pointed to. In that case, the pointer is just like an integer. In libfov’s case, the pointer is never dereferenced, just passed straight back to your callback, which itself can then cast to a C structure or C++ object pointer (because you’re back in your own territory where you know what data type that pointer should be).

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123