D casting broke?
Steven Schveighoffer via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Mon Jun 20 16:35:28 PDT 2016
On 6/19/16 5:19 PM, Joerg Joergonson wrote:
> On Sunday, 19 June 2016 at 20:21:35 UTC, ag0aep6g wrote:
>> On 06/19/2016 09:59 PM, Joerg Joergonson wrote:
>>> This should be completely valid since B!T' obviously derives from A!T
>>> directly
>>
>> ok
>>
>>> and we see that T' derives from b which derives from a
>>> directly.
>>
>> ok
>>
>>> So B!b is an entirely derived from A!a
>>
>> No. B!b is derived from A!b, not from A!a. `b` being derived from `a`
>> does not make A!b derived from A!a.
>
> why not? This doesn't seem logical!
Because:
class A(T : a)
{
static if(is(T == a))
int oops;
...
}
Now A!b and A!a have different layouts. They cannot be related, even if
the template arguments are related. I could introduce another virtual
function inside the static if, same result -- vtable is messed up.
In general, an instantiation of a template aggregate (class or struct)
is not castable implicitly to another instantiation of the same
aggregate unless explicitly declared.
And note that D does not allow multiple inheritance. I don't think you
can solve this problem in D.
-Steve
More information about the Digitalmars-d-learn
mailing list