Issue with casting types

Thorsten Sommer via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Tue May 17 05:24:15 PDT 2016


Dear all,

I run into an issue with a simple cast:
https://dpaste.dzfl.pl/8e7f7c545eb1

I have a base class and a class A with inherit from that base 
class:
A <- BaseClass

If the base class contains an "alias this", any casting attempt 
fails because the "alias this" type gets considered. Thus, I 
defined the opCast() to solve this. But now, the program crashes 
without any error or exception...

Why does the casting operation consider the "alias this" at all? 
I mean: The "alias this" type is int. If I try to cast with to!A, 
obviously int does not match A!?

Is there any practical solution? Or should I stop using "alias 
this" for my classes? I like the "alias this" concept. But it 
caused some issue for me...


Best regards,
Thorsten


More information about the Digitalmars-d-learn mailing list