Thread overview |
---|
July 27, 2009 small questions | ||||
---|---|---|---|---|
| ||||
Hello D community, Thank you for the interesting D :) Before sorry about bad English. class Foo{int i;this(int ii){i = ii}} new Foo(); new Foo(); Is iterator possible? foreach(Foo foo ;Foo) foo.i++; It get opapply error? add data in text. \0 \1 \2 \3 Is ok ? thank you! |
July 27, 2009 Re: small questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to harry | Reply to Harry,
> Hello D community,
>
> Thank you for the interesting D :)
> Before sorry about bad English.
>
> class Foo{int i;this(int ii){i = ii}}
> new Foo();
> new Foo();
>
> Is iterator possible?
> foreach(Foo foo ;Foo)
> foo.i++;
> I get opapply error?
If you want to iterate over several Foo objects you can put them in an array like this:
Foo[] fooArr = [ new Foo(1), new Foo(2) ];
foreach(Foo foo; fooArr)
foo.i++;
If you want to iterate over every Foo ever created, you will need to do something else (like have the constructor keep a list of Foo objects it has created).
|
July 28, 2009 Re: small questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to BCS | BCS Wrote:
> Reply to Harry,
>
> > Hello D community,
> >
> > Thank you for the interesting D :)
> > Before sorry about bad English.
> >
> > class Foo{int i;this(int ii){i = ii}}
> > new Foo();
> > new Foo();
> >
> > Is iterator possible?
> > foreach(Foo foo ;Foo)
> > foo.i++;
> > I get opapply error?
>
> If you want to iterate over several Foo objects you can put them in an array like this:
>
> Foo[] fooArr = [ new Foo(1), new Foo(2) ];
> foreach(Foo foo; fooArr)
> foo.i++;
>
> If you want to iterate over every Foo ever created, you will need to do something else (like have the constructor keep a list of Foo objects it has created).
>
>
thank you !
static array in class you mean?
|
July 28, 2009 Re: small questions | ||||
---|---|---|---|---|
| ||||
Posted in reply to Harry | Reply to Harry,
> BCS Wrote:
>
>> Reply to Harry,
>>
>>> Hello D community,
>>>
>>> Thank you for the interesting D :)
>>> Before sorry about bad English.
>>> class Foo{int i;this(int ii){i = ii}}
>>> new Foo();
>>> new Foo();
>>> Is iterator possible?
>>> foreach(Foo foo ;Foo)
>>> foo.i++;
>>> I get opapply error?
>> If you want to iterate over several Foo objects you can put them in
>> an array like this:
>>
>> Foo[] fooArr = [ new Foo(1), new Foo(2) ];
>> foreach(Foo foo; fooArr)
>> foo.i++;
>> If you want to iterate over every Foo ever created, you will need to
>> do something else (like have the constructor keep a list of Foo
>> objects it has created).
>>
> thank you !
> static array in class you mean?
That would be one options.
|
Copyright © 1999-2021 by the D Language Foundation