digitalmars.D.learn - Deriving a D-class from a CPP-class
- Alain De Vos (25/25) Apr 28 2021 Is it ok to do the following ?
- Alain De Vos (8/8) Apr 28 2021 PS: I managed to link to phobo's/runtime & wxgtk at the same time.
- Alain De Vos (20/20) Apr 28 2021 Following code produces a linker error.
- Adam D. Ruppe (5/15) Apr 28 2021 idk what you intend to do with this, this pattern is for merging
- evilrat (2/4) Apr 28 2021 It's virtual by default. The opposite is `final`.
- user1234 (2/8) Apr 29 2021 by default, excepted if protection is private or package.
Is it ok to do the following ? I.e. derive a D-class from a CPP-class. The compiler did not complained, and it was OK for him. ``` c++ -c MyClass.cpp ldc2 main.d MyClass.o -L-lstdc++ ``` ``` extern(C++){ class MyClass { public: int num=1; void myMethod(); }; }; class Derived : MyClass{ }; int main(){ Derived myObj; myObj.myMethod(); return 0; } ``` Could I use this method for using the C++-WXWIDGETS library directly?
Apr 28 2021
PS: I managed to link to phobo's/runtime & wxgtk at the same time. It goes like this [So someone does not need to re-invent the weel] ``` ldc2 - c test.d c++ test.o -o test -L/usr/local/lib -lphobos2-ldc -ldruntime-ldc -Wl,--gc-sections -lexecinfo -lpthread -lm -m64 `wxgtk3u-3.0-config --cxxflags --libs` ```
Apr 28 2021
Following code produces a linker error. d: error: undefined symbol: wxApp::OnInit() ``` extern(C++) {class wxApp { public: bool OnInit(); //virtual bool Oninit(); } } class MYAPP: wxApp { alias OnInit=wxApp.OnInit; bool OnInit(){return true;}; } int main(){ return 0; } ``` It is rather clear what I want to achieve but virtual functions give me headache because dlang does not now the word virtual.
Apr 28 2021
On Wednesday, 28 April 2021 at 19:46:00 UTC, Alain De Vos wrote:Following code produces a linker error. d: error: undefined symbol: wxApp::OnInit() ``` extern(C++) {class wxApp { public: bool OnInit(); //virtual bool Oninit();you mean `abstract` for that one?alias OnInit=wxApp.OnInit;idk what you intend to do with this, this pattern is for merging overloads not overridingbool OnInit(){return true;};and you might want `override` there
Apr 28 2021
On Wednesday, 28 April 2021 at 19:46:00 UTC, Alain De Vos wrote:It is rather clear what I want to achieve but virtual functions give me headache because dlang does not now the word virtual.It's virtual by default. The opposite is `final`.
Apr 28 2021
On Thursday, 29 April 2021 at 06:38:53 UTC, evilrat wrote:On Wednesday, 28 April 2021 at 19:46:00 UTC, Alain De Vos wrote:by default, excepted if protection is private or package.It is rather clear what I want to achieve but virtual functions give me headache because dlang does not now the word virtual.It's virtual by default. The opposite is `final`.
Apr 29 2021