[Issue 1493] New: Problem with dynamic array

d-bugmail at puremagic.com d-bugmail at puremagic.com
Tue Sep 11 03:12:26 PDT 2007


http://d.puremagic.com/issues/show_bug.cgi?id=1493

           Summary: Problem with dynamic array
           Product: D
           Version: 1.021
          Platform: PC
        OS/Version: Windows
            Status: NEW
          Severity: major
          Priority: P2
         Component: DMD
        AssignedTo: bugzilla at digitalmars.com
        ReportedBy: keystuffs at netscape.net


The dynamic array seems to be shared with all instances of a class:

class A {
  int array1[]  = [0]; // dynamic array
  int array2[1] = [0]; // static array
}

int main(char[][] p) {
  A a1 = new A();
  A a2 = new A();

  a1.array1[0] = 10;
  std.stdio.writefln(a1.array1[0]); // write 10: OK
  std.stdio.writefln(a2.array1[0]); // write 10: should be 0 

  a1.array2[0] = 20;
  std.stdio.writefln(a1.array2[0]); // write 20: OK
  std.stdio.writefln(a2.array2[0]); // write 0:  OK

  return 0;
}

So I think that the variable array1 is shared with the objects a1 and a2.


-- 



More information about the Digitalmars-d-bugs mailing list