Foreach problem

Bill Baxter wbaxter at gmail.com
Sat Jan 10 19:10:39 PST 2009


On Sun, Jan 11, 2009 at 12:04 PM, Tim M <a at b.com> wrote:
> On Sun, 11 Jan 2009 15:59:26 +1300, Tim M <a at b.com> wrote:
>> Why does it still work for some objects?
>
>
> This works:
>
>
> module test;
>
> class A
> {
>        this()
>        {
>                //
>        }
> }
>
> class B
> {
>        this()
>        {
>                //
>        }
>        int opApply (int delegate (inout B) dg)
>        {
>                return 1;
>        }
> }
>
> void main()
> {
>        A a;
>        B b;
>        foreach(a; b)
>        {
>                //
>        }
> }

Interesting.  But there the inner 'a' is actually a B.  So it
compiles, but there's no way it's using the outer 'a' as the counter
variable.

--bb


More information about the Digitalmars-d-learn mailing list