Is it possible to create a static factory method on a templated struct?

Gary Willoughby via Digitalmars-d-learn digitalmars-d-learn at puremagic.com
Sat Jun 18 09:05:53 PDT 2016


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?


More information about the Digitalmars-d-learn mailing list