Virtual functions and inheritance
Tobias Pankrath via Digitalmars-d-learn
digitalmars-d-learn at puremagic.com
Tue Jan 27 02:43:02 PST 2015
> -----
> class Bar
> {
> static T construct(this T, A...)(A a)
> {
> return new T(a);
> }
> }
> ----
>
I think it's a bug that you can use a template this parameter
(this T) on a static member function without a direct compilation
error.
> -----
> class Bar
> {
> static typeof(this) construct(A...)(A a)
> {
> return new typeof(this)(a);
> }
> }
>
Because it's exactly the same to write it as
static Bar construct(A...)(A a) { return new Bar(a); }
Of course this does not work. I don't know how to do it without
one line of boilerplate per class or without supplying the type
via template argument.
std.container.util : make takes the type to construct as an
argument, but std.container do not form a class hierarchy.
More information about the Digitalmars-d-learn
mailing list