array setting with objects (bug?)

Denton Cockburn diboss at hotmail.com
Tue Mar 4 05:32:00 PST 2008


Is this a bug?

import std.stdio;

class C
{
	int[] x;
}

void main()
{
	C[] arr;
	arr.length = 3;
	arr[] = new C; /* this is the offending line, it doesn't happen if I */
			/*initalize each independently */
	
	foreach (ref c; arr)
	{
		c.x ~= 5;
		writefln(c.x);
	}
}

the printed result is:
[5]
[5,5]
[5,5,5]

I expected it to be:
[5]
[5]
[5]

I didn't find any explanation for this kind of behaviour in the docs, and
it does seem like a bug to me.



More information about the Digitalmars-d mailing list