digitalmars.D.learn - Is it possible to create a static factory method on a templated
- Gary Willoughby (21/21) Jun 18 2016 I've tried the following code and I get the error:
- ketmar (7/8) Jun 18 2016 you still have to instantiate you `Foo` here:
I've tried the following code and I get the error: Error: template Foo(A) does not have property 'of' struct Foo(A) { private int _foo; disable this(); public this(int foo) { this._foo = foo; } public static auto of(B)() { return Foo!(B)(8); } } void main(string[] args) { auto foo = Foo.of!(string); } Is it possible to even have static methods on structs like this? What am I doing wrong?
Jun 18 2016
On Saturday, 18 June 2016 at 16:05:53 UTC, Gary Willoughby wrote:I've tried the following code and I get the error:you still have to instantiate you `Foo` here: auto foo = Foo.of!(string); no, you can't call even static methods of *uninstantiated* template. uninstantiated template doesn't exist at all. this works, for example: auto foo = Foo!int.of!(string);
Jun 18 2016