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