Re: Class member initialization with new points to a single instance?

2021-06-09 Thread mw via Digitalmars-d-learn
On Wednesday, 9 June 2021 at 18:12:01 UTC, Gregor Mückl wrote: On Wednesday, 9 June 2021 at 18:04:54 UTC, evilrat wrote: On Wednesday, 9 June 2021 at 17:56:24 UTC, Gregor Mückl wrote: Consider the following code: ```d class Foo { } class Bar { Foo foo = new Foo(); } void main() {

Re: Class member initialization with new points to a single instance?

2021-06-09 Thread Gregor Mückl via Digitalmars-d-learn
On Wednesday, 9 June 2021 at 18:04:54 UTC, evilrat wrote: On Wednesday, 9 June 2021 at 17:56:24 UTC, Gregor Mückl wrote: Consider the following code: ```d class Foo { } class Bar { Foo foo = new Foo(); } void main() { Bar b1 = new Bar(); Bar b2 = new Bar();

Re: Class member initialization with new points to a single instance?

2021-06-09 Thread evilrat via Digitalmars-d-learn
On Wednesday, 9 June 2021 at 17:56:24 UTC, Gregor Mückl wrote: 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

Re: Class member initialization with new points to a single instance?

2021-06-09 Thread Adam D Ruppe via Digitalmars-d-learn
On Wednesday, 9 June 2021 at 17:56:24 UTC, Gregor Mückl wrote: class Bar { Foo foo = new Foo(); } This is a static initialization The assert fails. This is completely surprising to me. Is this actually expected? Yes, it is expected if you are familiar with the spec. All member = x

Class member initialization with new points to a single instance?

2021-06-09 Thread Gregor Mückl via Digitalmars-d-learn
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?