On Sunday, 8 April 2018 at 13:00:02 UTC, bauss wrote:


// a.d
module a;

class Foo
        bool _baz;
        void handleBar(T : Foo)(T[] foos)
                foreach (child; foos)
                        child._baz = true; // Not ok.

replace this line with

   import std.stdio;

This writelns:

   void a.Foo.handleBar!(Bar).handleBar(Bar[] foos)
   [b.Bar, b.Bar]

So foos is actually an array of Bars. And there is no access from a Bar to the private elements of it's baseclass Foo.

What I am wondering about is why does the method template match in the first place?

                        (cast(Foo)child)._baz = true; // Ok.

You also may use the ternary conditional operator for that (SCNR).

Reply via email to