How to use inheritance when interfacing with C++ classes?

rempas rempas at tutanota.com
Thu Dec 9 19:05:08 UTC 2021


I would like to interface with a C++ library called 
[FLTK](https://www.fltk.org/). I'm trying to implement the 
binding for the classes based to what I've read 
[here](https://dlang.org/spec/cpp_interface.html#classes) but it 
seems that It doesn't work as expected for me. I want to 
implement the "abstract" class "Fl_Widget" and the class 
"Fl_Group" which inherits from the "Fl_Widget". I will put a part 
of the code as there is no reason to put the whole code and make 
the post unnecessarily big. If in any case however, you need the 
whole reference: 
[Fl_Widget](https://fltk.gitlab.io/fltk/classFl__Widget.html) and 
[Fl_Group](https://fltk.gitlab.io/fltk/classFl__Group.html). Here 
is the code:

```
extern(C++) {
   abstract class Fl_Widget {
     void   _clear_fullscreen();
     void   _set_fullscreen();
   }

   class Fl_Group : Fl_Widget {
     ref Fl_Widget*    _ddfdesign_kludge();
     void              add(ref Fl_Widget);
     void              add(Fl_Widget*o);
   }
}
```

Normally this should work but the "Fl_Group" class makes in bug 
and I'm getting the following error message:

```
Linking...
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.098.0-A4E26D206D34B9B9CA1A0366B3CE0F2C/dfltk.o:(.data._D4test8Fl_Group6__vtblZ+0x0): undefined reference to `Fl_Widget::_clear_fullscreen()'
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.098.0-A4E26D206D34B9B9CA1A0366B3CE0F2C/dfltk.o:(.data._D4test8Fl_Group6__vtblZ+0x8): undefined reference to `Fl_Widget::_set_fullscreen()'
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.098.0-A4E26D206D34B9B9CA1A0366B3CE0F2C/dfltk.o:(.data._D4test8Fl_Group6__vtblZ+0x10): undefined reference to `Fl_Group::_ddfdesign_kludge()'
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.098.0-A4E26D206D34B9B9CA1A0366B3CE0F2C/dfltk.o:(.data._D4test8Fl_Group6__vtblZ+0x18): undefined reference to `Fl_Group::add(Fl_Widget*&)'
/usr/bin/ld: 
.dub/build/application-debug-linux.posix-x86_64-dmd_v2.098.0-A4E26D206D34B9B9CA1A0366B3CE0F2C/dfltk.o:(.data._D4test8Fl_Group6__vtblZ+0x20): undefined reference to `Fl_Group::add(Fl_Widget**)'
collect2: error: ld returned 1 exit status
Error: linker exited with status 1
```

Anyone has an idea?


More information about the Digitalmars-d-learn mailing list