Foreach problem

Tim M a at b.com
Sat Jan 10 19:15:03 PST 2009


On Sun, 11 Jan 2009 16:10:39 +1300, Bill Baxter <wbaxter at gmail.com> wrote:

> 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

Sorry for my typo but change that line to:
int opApply (int delegate (inout A) dg)

and it still compiles.



More information about the Digitalmars-d-learn mailing list