Re: Deriving a D-class from a CPP-class

2021-04-29 Thread user1234 via Digitalmars-d-learn

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:


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`.


by default, excepted if protection is private or package.


Re: Deriving a D-class from a CPP-class

2021-04-28 Thread evilrat via Digitalmars-d-learn

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`.


Re: Deriving a D-class from a CPP-class

2021-04-28 Thread Adam D. Ruppe via Digitalmars-d-learn

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 overriding



bool OnInit(){return true;};


and you might want `override` there



Re: Deriving a D-class from a CPP-class

2021-04-28 Thread Alain De Vos via Digitalmars-d-learn

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.


Re: Deriving a D-class from a CPP-class

2021-04-28 Thread Alain De Vos via Digitalmars-d-learn

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`


```


Deriving a D-class from a CPP-class

2021-04-28 Thread Alain De Vos via Digitalmars-d-learn

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?