Why are class methods not allowed to call cons/destructors?

Tejas notrealemail at gmail.com
Sat Jul 31 13:12:21 UTC 2021


```d
class A{
     ~this(){}
     destructA(){
         ~this()
     }
}
class B:A{
     ~this(){}
     destructB(){
         ~this();
         ~super();
     }
}

```
This could allow ```@nogc``` crowd to run destructors without 
calling ```destroy```.
Yes, derived to base conversion is still a thing and someone who 
invokes the destructor just by looking at the parameter's type 
could get fooled, atleast we will have a way to destroy class 
instances without the gc.

Are there other problems? I'm genuinely curious.

I guess we can still just define normal methods and invoke them, 
but atleast this will allow us to maintain consistency with the 
gc crowd.


More information about the Digitalmars-d-learn mailing list