extern(C++): override nonvirtual member function
evilrat
evilrat666 at gmail.com
Fri Apr 25 05:24:55 UTC 2025
On Thursday, 24 April 2025 at 19:41:48 UTC, sfp wrote:
> I'm trying to wrap some C++ classes, and one issue I've run
> into is having an extern(C++) class inheriting from another,
> with the child doing a "nonvirtual override" of a nonvirtual
> member function in the base class... E.g., in C++:
> ```
> struct A {
> void f() { ... }
> ...
> // some other virtual functions
> };
>
> struct B {
> void f() { ... } // nonvirtual override A::f
> ...
> // other VFs
> };
> ```
> D doesn't seem to like this very much... Is there some way to
> hack around this issue? For a variety of reasons, I can't make
> any modifications to the C++ code I'm wrapping.
>
> For more context, I'm writing a script that's generating
> wrappers for about 150 header files, maybe 100-200k LOC (using
> the cxxheaderparse Python library). This is actually going
> pretty well, but he best solution I can come up with right now
> is to try to detect cases like this and omit them, but it's
> less than ideal. The C++ library is mostly C++98 style and it's
> been smooth sailing with the occasional wart I've needed to
> figure out like this.
both f() would be marked `final` in D which will tell it is
'nonvirtual override', and then you will have more headache.
check this example on how C++ behavior depends on how it was laid
out in code...
https://godbolt.org/z/qojxM5Tj7
More information about the Digitalmars-d-learn
mailing list