|
Archives
D Programming
DD.gnu digitalmars.D digitalmars.D.bugs digitalmars.D.dtl digitalmars.D.ide digitalmars.D.dwt digitalmars.D.announce digitalmars.D.learn digitalmars.D.debugger C/C++ Programming
c++c++.announce c++.atl c++.beta c++.chat c++.command-line c++.dos c++.dos.16-bits c++.dos.32-bits c++.idde c++.mfc c++.rtl c++.stl c++.stl.hp c++.stl.port c++.stl.sgi c++.stlsoft c++.windows c++.windows.16-bits c++.windows.32-bits c++.wxwindows digitalmars.empire digitalmars.DMDScript electronics |
D - Behavior of "auto"
A strange effect of using auto:
The following code:
import std.stdio;
class Test {
this() {
printf("Created\n");
}
~this() {
printf("Destroyed\n");
}
}
int main(char[][] args){
for (int n = 0; n < 10; n++)
Test t = new Test();
return 0;
}
produces the following output:
Created
Created
Created
Created
Created
Created
Created
Created
Created
Created
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
Destroyed
where as changing the line:
Test t = new Test();
to:
auto Test t = new Test();
produces:
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
Created
Destroyed
As I understand it, one would expect this to be the effect of "scope," not
"auto." Can someone explain why this happens?
Thanks in advance.
Dec 05 2007
this NG is depricated you should use the digitalmars.D groups Dec 06 2007
|