typeid + toString = runtime error

Zhenya zheny at list.ru
Sun Dec 30 08:09:02 PST 2012


On Sunday, 30 December 2012 at 16:04:48 UTC, Ali Çehreli wrote:
> On 12/30/2012 07:32 AM, Zhenya wrote:
>> Hi!
>> Explain me please why this code fails in runtime:
>>
>> import std.stdio;
>>
>> class Foo
>> {
>> ~this() {writeln(typeid(this).toString ~ "is dead");}
>> }
>>
>> void main()
>> {
>> new Foo;
>> }
>>
>> Application error:
>> core.exception.InvalidMemoryOperationError
>
> My guess is that by the time that destructor is executed, the 
> runtime has been shut down sufficiently that the ~ operator 
> cannot work. The following has the same error:
>
> import std.stdio;
>
> string foo()
> {
>     return "abc";
> }
>
> class Foo
> {
>     ~this() {writeln(foo() ~ "xyz");}
> }
>
> void main()
> {
>     new Foo;
> }
>
> Ali

Thank you,now all is clear for me.


More information about the Digitalmars-d-learn mailing list