new A().b() currently requires extra brackets/parentheses
Nick Treleaven
ntrel-public at yahoo.co.uk
Sun Sep 9 08:16:30 PDT 2012
On 09/09/2012 14:39, Ben Davis wrote:
>
> On 09/09/2012 14:23, Philippe Sigaud wrote:
> > you could use factory functions:
> >
> > class A {}
> >
> > A a() { return new A();}
>
> Good idea. It might not work so well for me because the user might also
> be creating custom GUI components and would therefore have to create
> their own factory functions, but thanks for the idea in any case.
Maybe you could use a template:
auto create(T, Args...)(Args args)
{
return new T(args);
}
class A
{
int i;
this(int i){this.i = i;}
}
import std.stdio;
void main()
{
create!A(5).i.writeln();
}
But I agree with you it would be nice if dmd supported 'new A().b()'.
More information about the Digitalmars-d
mailing list