[Issue 11946] "need 'this' to access member" when passing field to template parameter
via Digitalmars-d-bugs
digitalmars-d-bugs at puremagic.com
Tue Jul 15 02:12:57 PDT 2014
https://issues.dlang.org/show_bug.cgi?id=11946
--- Comment #45 from Kenji Hara <k.hara.pg at gmail.com> ---
(In reply to timon.gehr from comment #44)
> For one thing, what if I want to make some members of my template scope static
> and not others?
>
> class C{
> int x;
> template T(alias a){
> int foo(){ return x; }
> static int bar(int y){ return a(y); }
> }
> }
>
> Just because I don't want bar to be a member function of class C, with the
> new behaviour I now _also_ disable local instantiation. What is this?
foo will become member function, and bar will become static member function.
void main()
{
C c = new C();
c.x = 5;
static int g(int n) { return n*10; }
assert(c.T!g.foo() == 5); // foo is member function
assert(C.T!g.bar(2) == 20); // bar is static member function
}
--
More information about the Digitalmars-d-bugs
mailing list