Why are class methods not allowed to call cons/destructors?
Tejas
notrealemail at gmail.com
Sat Jul 31 13:52:08 UTC 2021
On Saturday, 31 July 2021 at 13:34:25 UTC, user1234 wrote:
> 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.
Both solutions also suffer from ```cast```, so one is not better
than another(except that your solution doesn't require a language
change, which makes it more feasible to use).
I'm simply curious why the requested behaviour is not available
in the first place.
More information about the Digitalmars-d-learn
mailing list