Re: Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
That's a fantastic answer! Thank you. I was not aware that initializers were always compile time, that was the missing piece in my understanding. It's a shame that I can't use the nicer (IMO) syntax, but the reasoning is sound.

Field Initialiser Reused Across Object Instances

2021-01-01 Thread Adam via Digitalmars-d-learn
Consider the following: class A { int x; } class B { A a = new A; // I would expect this to be called for each "new B". } void main() { import std.stdio; auto c = new B; writeln("c ", c.a.x); c.a.x++; writeln("c ", c.a.x); writeln; auto d = new B;

Template Oriented Programming

2015-09-17 Thread Adam via Digitalmars-d-learn
I'm not sure if "Template Oriented Programming" seems to be the way to go in D, but I've got my head mainly stuck around OOP. I'm a bit confused about how to dive into it. With OOP, we create interfaces, which provide a contract that all implementers of the interface have to abide by.