On Friday, 24 August 2012 at 05:14:39 UTC, F i L wrote:
We replace it with special factory functions. Example:class Person { string name; uint age; this new(string n, uint a) { name = n; age = a; } } void main() { auto philip = Person.new("Philip", 24); }Notice 'new()' returns type 'this', which makes it static and implicitly calls allocation methods (which could be overridden) and has a 'this' reference.
The constructor definition syntax doesn't seem to be an improvement: this new instead of the old this.
The constructor calling syntax is actually something I've thought of before. I think Class.new is better than new Class, simply because it's more succinct when chaining:
Class.new().method() vs. (new Class()).method() NMS
