Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You can't actually export C++ classes directly like this.</p> <pre><code>static extern void functionFromClass(); </code></pre> <p>The problem with C++ is that it doesn't have a universally defined ABI (Application binary interface). So In order to make other languages understand your C++ library ABI you need to wrap it with C functions (almost every other language understands C).</p> <p>The problem with C is that it doesn't understand classes. On the other hand, C++ Objects need to pass <code>this</code> pointer as a parameter to their member functions. So in order to wrap your C++ classes with C interface. You need to handle passing <code>this</code> parameter explicitly and also define functions similar to the constructor and destructor. </p> <p>You need to do sth like this:</p> <pre><code>//Header File Foo.h struct Foo; // Forward Declaration Only Foo* createFoo( /* parameters */ ); void destroyFoo( Foo* obj ); int Func( Foo* obj, int i ); // obj should take this pointer float Func2( Foo* obj, float i, float j ); </code></pre> <p>Implement it like this</p> <pre><code>#include "Foo.h" extern "C" { Foo* createFoo( const char * s ) { return reinterpret_cast&lt;Foo*&gt;( new Foo( s ) ); } void destroyFoo( Foo* obj ) { delete reinterpret_cast&lt;Foo*&gt;(obj ); } int Func( Foo* obj, int i ) { return reinterpret_cast&lt;Foo*&gt;(obj)-&gt;Func(i); } } </code></pre> <p>Finally you can wrap your exported C function in a C# class so things get back to the traditional object oriented way.</p> <p>Notice that I didn't even mention Inheritance or polymorphism.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload