digitalmars.D - Calling an alias for a Class method in another scope
- d coder <dlang.coder gmail.com> May 31 2012
--f46d0401fc3fea47fa04c15e9243
Content-Type: text/plain; charset=ISO-8859-1
Greetings
Kindly make me understand this. I have been trying to call an alias for a
class method from another scope. I keep getting an error saying that I need
"this" to call a method. Why will not "this" pointer be available when I am
passing the method symbol along with an object of the class? Is there
another way of doing what I am trying to achieve. I have pasted a sample
code below here.
Regards
- Puneet
void callfoo(alias F, T) (T t) {
void foo() {
F(); // Error: need 'this' to access member foo
t.F(); // Error: undefined identifier 'F'
}
}
class Foo {
void foo() {}
}
void main() {
Foo f = new Foo();
callfoo!(f.foo)(f);
}
--f46d0401fc3fea47fa04c15e9243
Content-Type: text/html; charset=ISO-8859-1
Content-Transfer-Encoding: quoted-printable
Greetings<div><br></div><div>Kindly make me understand this. I have been tr=
ying to call an alias for a class method from another scope. I keep getting=
an error saying that I need "this" to call a method. Why will no=
t "this" pointer be available when I am passing the method symbol=
along with an object of the class? Is there another way of doing what I am=
trying to achieve. I have pasted a sample code below here.</div>
<div><br></div><div>Regards</div><div>- Puneet</div><div><br></div><div><di=
v>void callfoo(alias F, T) (T t) {</div><div>=A0 void foo() {</div><div>=A0=
=A0 F(); =A0 // Error: need 'this' to access member foo</div><div>=
=A0 =A0 t.F(); // Error: undefined identifier 'F'</div>
<div>=A0 }</div><div>}</div><div><br></div><div>class Foo {</div><div>=A0 v=
oid foo() {}</div><div>}</div><div><br></div><div>void main() {</div><div>=
=A0 Foo f =3D new Foo();</div><div>=A0 callfoo!(f.foo)(f);</div><div>}</div=
</div>
<div><br></div>
--f46d0401fc3fea47fa04c15e9243--
May 31 2012








d coder <dlang.coder gmail.com>