subclass to base class but not subclass pointer to base class pointer?

Namespace rswhite4 at googlemail.com
Sat Apr 20 09:36:08 PDT 2013


On Saturday, 20 April 2013 at 15:34:50 UTC, John Colvin wrote:
> On Saturday, 20 April 2013 at 15:32:20 UTC, Andrej Mitrovic 
> wrote:
>> On 4/20/13, Namespace <rswhite4 at googlemail.com> wrote:
>>> Why can D implicitly cast from the subclass to the base class,
>>> but not implicitly from the subclasse pointer to the base 
>>> class
>>> pointer?
>>>
>>> This works: http://dpaste.1azy.net/30dd34a0
>>> This not: http://dpaste.1azy.net/ffacfd83
>>>
>>> Makes not much sense for me.
>>>
>>
>> I'd really recommend reading one of the D books before asking 
>> so many
>> fundamental questions: http://wiki.dlang.org/Books
>> And probably the spec too.
>>
>> Bottom line: D is not C++.
>
> It's not allowed in c++ either. See my original reply.

It works fine in C++ (of course with -std=c++0x)
http://codepad.org/qLIjGGd4

But thanks for your answer. I know that D classes a reference 
types but I was thinking that the compiler could detect what I 
want and could implicit cast.

>> I'd really recommend reading one of the D books before asking 
>> so many
>> fundamental questions: http://wiki.dlang.org/Books
>> And probably the spec too.

Not very helpful. But why "many"?
I cannot remember one "fundamental question".


More information about the Digitalmars-d-learn mailing list