On Sunday, 8 April 2018 at 13:00:02 UTC, bauss wrote:
I think it's better demonstrated like this, because to me the
behavior makes no sense.
Especially since you can just cast "Bar" to "Foo" and then
you're allowed to do it.
Since we're inside Foo then it shouldn't care whether "_baz" is
private or not.
I could understand if the function was located within Bar, but
It's perfectly normal in other languages that supports classes
to access private members of parent's as long as you're within
the parent's encapsulation.
void handleBar(T : Foo)(T foos)
foreach (child; foos)
child._baz = true; // Not ok.
(cast(Foo)child)._baz = true; // Ok.
class Bar : Foo
auto bars = [new Bar, new Bar];
auto bar = new Bar;
Actually, this behaves as i would expect.
`_baz` is a private member of Foo (to be precise: it belongs to
in handleBar(), you iterate `Bar` - which is in module `b`.
By casting it to Foo, you are accessing the wanted module (`a`)