Object "A" inherited object "B". And you need to return the object link "B".

Steven Schveighoffer schveiguy at gmail.com
Thu Feb 6 15:11:56 UTC 2020


On 2/6/20 8:05 AM, Mihail Lorenko wrote:
> On Thursday, 6 February 2020 at 12:37:01 UTC, Adam D. Ruppe wrote:
>> On Thursday, 6 February 2020 at 12:15:17 UTC, Mihail Lorenko wrote:
>>>>     B* b;
>>
>> A pointer to a class is a rare thing in B since they are already 
>> automatic references. Just use `B b;` and ten `b = a` will just work.
> 
> Thanks for the answer!
> Well, apparently I have to get around my problem. Thanks again!

Not sure, but you might misunderstand. B is already a pointer in D (like 
Java, D's class instances are always references).

And derived classes implicitly cast to base classes. So the a.B syntax 
is not necessary.

To illustrate further:

A a = new A; // note, instances by default are null, you need to new them
B b = a; // implicit cast

assert(a is b); // they are the same object
b.step(); // virtual call, calls B.step

assert(a.a != 0); // note, protected allows access from same module.

-Steve


More information about the Digitalmars-d-learn mailing list