C++'s this() equivalent?
zjh
fqbqrr at 163.com
Thu Jun 15 15:15:53 UTC 2023
```d
import core.stdc.stdio;
struct A{
static int e=40;
struct B{
int m;
this(int i){
printf("%i",e);m=i;
}
~this(){
e=m;
printf("%i",e);
}
}
void f(){
B b=e;e=6;
}
void g(){
printf("%i",e);
}
}
extern(C)void main(){
A a;
a.f();
a.g();
}
```
I want `B` to become the following version similar to 'C++'. What
should I do?
```cpp
struct B{
int m;
B(){
printf("%i",e);m=e;
}
~B(){
e=m;
printf("%i",e);
}
}
```
Thank you.
More information about the Digitalmars-d-learn
mailing list