Interfacing with basic C++ class

Ogi ogion.art at gmail.com
Thu Sep 29 11:13:15 UTC 2022


On Wednesday, 28 September 2022 at 19:57:10 UTC, Riccardo M wrote:
> I think I am stuck in the easiest of the issues and yet it 
> seems I cannot get around this.
> I have a C++ file:
> ```
> class MyClass {
> public:
>     int field;
>     MyClass(int a) : field(a) {}
>
>     int add(int asd) {
>         return asd + 1;
>     }
> };
> ```

Ali is correct. However, you don’t have to change anything on the 
C++ side, just map C++ class to D struct:
```D
extern(C++, class) {
     struct MyClass {
     public:	
         int field;
         @disable this();
         int add(int asd); //struct fields are always `final`
     }

     MyClass* instantiate(int asd); //mind the *
}
```


More information about the Digitalmars-d-learn mailing list