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

user1234 user1234 at 12.fr
Sat Jul 31 13:34:25 UTC 2021


On Saturday, 31 July 2021 at 13:12:21 UTC, Tejas wrote:
> ```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.

`destroy` is not the problem, see

https://forum.dlang.org/post/jsrjgmeblfukwhqbwjab@forum.dlang.org

the problem is **what is called in `destroy()`**

see 
https://forum.dlang.org/post/rdqqqqcadsqsmszqgslr@forum.dlang.org

for a very simple solution.


More information about the Digitalmars-d-learn mailing list