Class member initialization with new points to a single instance?

Gregor Mückl gregormueckl at gmx.de
Wed Jun 9 17:56:24 UTC 2021


Consider the following code:

```d
class Foo {  }

class Bar { Foo foo = new Foo(); }

void main()
{
	Bar b1 = new Bar();
	Bar b2 = new Bar();

	assert(b1.foo != b2.foo);
}
```

The assert fails. This is completely surprising to me. Is this 
actually expected?


More information about the Digitalmars-d-learn mailing list