Re: Class-related queries [was: Re: 'Undefined reference' linking

2010-04-10 Thread bearophile
Lars T. Kyllingstad: > You don't have to write 'auto' to get type inference. You just have to > have something that signifies to the compiler that a variable is > declared. All of these are valid: > > auto x = 123; // x is int > const y = 1.23; // y is const(double) >

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-10 Thread Lars T. Kyllingstad
Joseph Wakeling wrote: Also try: foreach(uint i;0..1) { scope Foo f = new Foo(i); // Do something with f ... } That sometimes doesn't require allocations. To be sure I understand -- is there anything wrong with writing scope auto f = new Foo(i) ... or, in general, using auto

Re: Class-related queries

2010-04-09 Thread bearophile
Joseph Wakeling: > is there anything wrong with writing > scope auto f = new Foo(i) If the compiler is cool with that, then it's OK :-) Bye, bearophile

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread BCS
Hello Joseph, To be sure I understand -- is there anything wrong with writing scope auto f = new Foo(i) BTW, the following might work: scope f = new Foo(i); -- ... <

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread Joseph Wakeling
> Also try: > > foreach(uint i;0..1) { >scope Foo f = new Foo(i); >// Do something with f ... > } > > That sometimes doesn't require allocations. To be sure I understand -- is there anything wrong with writing scope auto f = new Foo(i) ... or, in general, using auto to infer the

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread bearophile
Joseph Wakeling: > ... when it reappears in D as: > > foreach(uint i;0..1) { > auto f = new Foo(i); > // Do something with f ... > } Also try: foreach(uint i;0..1) { scope Foo f = new Foo(i); // Do something with f ... } That sometimes doesn't require all

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread Joseph Wakeling
I wrote: > I guess I am worried about what could happen in the case of code like this in > C++: > > for(i=0;i<1;++i) { > Foo f(i); > // Do something with f ... > } > > ... when it reappears in D as: > > foreach(uint i;0..1) { > auto f = new Foo(i); >

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread Joseph Wakeling
Thanks for the interesting and detailed explanation. :-) > Now you see, 'new' is for dynamic memory allocation in D as well, it's > just that for classes it is required. You normally don't need to worry > about 'delete', as the GC will take care of deallocation. I guess I am worried about what c

Re: Class-related queries [was: Re: 'Undefined reference' linking errors]

2010-04-09 Thread Lars T. Kyllingstad
Joseph Wakeling wrote: I also have some C++ experience, but it seems to be confusing as much as complementary with respect to D ... :-) Current source of confusion relates to declaring objects of a class whose constructor takes input -- confusion because I can write, class Foo {