You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hey all! I've been using fbjni in a lot of libraries now, and now I stumbled upon an interesting task.
I have pure, shared C++ classes that define virtual methods. E.g. Car, and SportsCar which inherits from Car, overrides a few methods and adds some methods.
..and then how do I properly bridge them to C++ using fbjni? Can my fbjni class inherit from both the Java base, and the SportsCar base?
// JCar.cppstructJCar : publicjni::HybridClass<JCar>, public Car {
public:staticautoconstexprkJavaDescriptor = "Lcom/mrousavy/Car;";
doublegetSpeed() override {
// TODO: get `speed` from java part, with proper virtual lookup
}
boolisFast() override {
// TODO: get `isFast` from java part, with proper virtual lookup
}
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
staticvoidregisterNatives();
}
// JSportsCar.cppstructJSportsCar : publicjni::HybridClass<JSportsCar, JCar>, public SportsCar {
public:staticautoconstexprkJavaDescriptor = "Lcom/mrousavy/SportsCar;";
doublegetSpeed() override {
// TODO: get `speed` from java part, with proper virtual lookup
}
boolisFast() override {
// TODO: get `isFast` from java part, with proper virtual lookup
}
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
staticvoidregisterNatives();
}
Can I call initHybrid() in both base and inherited class? Do I now have two base instances of the same type (Car) in memory?
The text was updated successfully, but these errors were encountered:
mrousavy
changed the title
How to build a proper HybridClass inheritance?
How to represent C++ object inheritance as Java object inheritance using HybridClass?
Aug 16, 2024
Hey all! I've been using fbjni in a lot of libraries now, and now I stumbled upon an interesting task.
I have pure, shared C++ classes that define virtual methods. E.g.
Car
, andSportsCar
which inherits fromCar
, overrides a few methods and adds some methods.I want to resemble that C++ inheritance in Java, without adding something to those C++ classes (they are shared between platforms).
So my understanding is that I create the same types in Java:
..and then how do I properly bridge them to C++ using fbjni? Can my fbjni class inherit from both the Java base, and the SportsCar base?
Can I call
initHybrid()
in both base and inherited class? Do I now have two base instances of the same type (Car
) in memory?The text was updated successfully, but these errors were encountered: