www.digitalmars.com         C & C++   DMDScript  

digitalmars.D - Bug 0.86

reply one_mad_alien hotmail.com writes:
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
parent reply "Walter" <newshound digitalmars.com> writes:
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 03 2004
parent reply "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
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 03 2004
parent reply J Anderson <REMOVEanderson badmama.com.au> writes:
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 03 2004
parent "Unknown W. Brackets" <unknown at.simplemachines.dot.org> writes:
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]
May 03 2004