struct destructor

Alain De Vos devosalain at ymail.com
Sat May 15 19:58:55 UTC 2021


I'll try first the first tip of Adam, here the code,

```
import std.stdio:writeln;
import core.memory: GC;
void myfun(){
class C{
	int[10000] x;
	}//class C
	
struct S {
	C c=null;
	@disable this();

	this(int dummy) {
		c=new C();
		writeln("Constructor");
		};//Constructor

	~this(){
		writeln("Destructor");
		.destroy(c);
		void * address=GC.addrOf(cast(void *)c);
		GC.free(address);
		};//destructor
}//struct S
S mys=S(0);
};//myfun()

void main(){
	myfun();
};//main
```


More information about the Digitalmars-d-learn mailing list