Thread overview
Bug 0.86
May 03, 2004
one_mad_alien
May 03, 2004
Walter
May 04, 2004
J Anderson
May 03, 2004
the following does not see obj2 as a valid identifier until after this line where it is declared.

--------------- bugtest2.d -----------------------

class MyObj {}

int main( char[][] args ) {
MyObj obj;
obj = new typeof(obj);
MyObj obj2 = new typeof(obj2);
return 0;
}

//
// bugtest2.d(7): undefined identifier obj2
//



May 03, 2004
That's correct, a variable is not recognized until after it is initialized. -Walter

<one_mad_alien@hotmail.com> wrote in message news:c76jg8$o3q$1@digitaldaemon.com...
> the following does not see obj2 as a valid identifier until after this
line
> where it is declared.
>
> --------------- bugtest2.d -----------------------
>
> class MyObj {}
>
> int main( char[][] args ) {
> MyObj obj;
> obj = new typeof(obj);
> MyObj obj2 = new typeof(obj2);
> return 0;
> }
>
> //
> // bugtest2.d(7): undefined identifier obj2
> //
>
>
>


May 04, 2004
Walter wrote:
> That's correct, a variable is not recognized until after it is
> initialized. -Walter
> 
>>MyObj obj2 = new typeof(obj2);

It would be nice to be able to do that... (so as not to have to duplicate the name, makes renaming classes or changing classes much easier...) but far from necccessary.  And it would probably only serve to complicate the compiler if it were done...

-[Unknown]
May 04, 2004
Unknown W. Brackets wrote:

> Walter wrote:
>
>> That's correct, a variable is not recognized until after it is
>> initialized. -Walter
>>
>>> MyObj obj2 = new typeof(obj2);
>>
>
> It would be nice to be able to do that... (so as not to have to duplicate the name, makes renaming classes or changing classes much easier...) but far from necccessary.  And it would probably only serve to complicate the compiler if it were done...
>
> -[Unknown]

It would be even better if you could write short hand something like:

MyObj new obj2;

-- 
-Anderson: http://badmama.com.au/~anderson/
May 04, 2004
J Anderson wrote:
> It would be even better if you could write short hand something like:
> 
> MyObj new obj2;

Hmm, I would suggest that this would be a bit more logical reading it:

	new MyObj obj2;

But, then, it might get confusing when compared to:

	new MyObj();

Although, that does beg the question of whether you want this...

	MyObj new obj2(2, 3), obj3(4, 5);

But, really, this is all laziness, because the following isn't all that hard to type:

	MyObj obj2 = new MyObj(2, 3), obj3 = new MyObj(4, 5);

-[Unknown]