Replies: 1 comment 1 reply
-
Sounds interesting. Recently I was looking for a way to do something like this:
but I couldn't find a way in the time I gave it and instead feel back to using embedding (here JIC someone is curious). What you have in mind, could that also solve this?
If you send a draft PR I'll definitely look. No need to polish or make it work on all platforms, but a minimal test that works on at least one platform seems important. |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
In the GObject* (and others, such as QEMU's qdev) type system, C-compatible 'inheritance' is implemented by embedding the parent struct in the child struct:
One can already implement a polymorphic_type_hook to go from
Parent
toChild
objects, but currently you can't do:Because it requires
std::is_base_of<Child, Parent>
to be true, which isn't true for GObject types. Adding an overload forstd::is_base_of
doesn't address the issue (and is a really bad idea anyways).I theorize that I can very simply implement support for this by adding an attribute that (1) adds a base with a custom cast mechanism, and (2) marks the instance as non-simple (in the same way that virtual/multiple inheritance is implemented). Likely less than a dozen lines of code. It'd probably look like this:
@rwgk @Skylion007 if implemented, would you accept this in pybind11? If so, I can put some time into adding proper tests and make a PR once it works. If not, I'll just keep it locally since I'll need it for something.
Beta Was this translation helpful? Give feedback.
All reactions