Notice: On April 23, 2014, Statalist moved from an email list to a forum, based at statalist.org.
From | Richard Foltyn <richard.foltyn@gmail.com> |
To | statalist@hsphsun2.harvard.edu |
Subject | st: Pointer to class member function? |
Date | Fri, 3 May 2013 15:36:56 +0200 |
Dear Listers, I need to create a pointer to a class member function, but cannot figure out how to do that. The usual way of using &func() does not work, and neither do other "obvious" alternatives such as &this.func() or &(this.func)(). Here is a demo code that does nothing useful to illustrate what I am trying to achieve: mata class testClass { void run1() void run2() real scalar func() } real scalar testClass::func(real scalar arg) { return(arg) } void testClass::run2(pointer(real scalar function) scalar f, /// real scalar arg) { (*f)(arg) } void testClass::run1() { this.run2(&func(), 1) } foo = testClass() foo.run1() end Running this I get the error message: : foo.run1() testClass::run1(): 3499 func() not found [3] <istmt>: - function returned error [1] Thanks for your help! Richard * * For searches and help try: * http://www.stata.com/help.cgi?search * http://www.stata.com/support/faqs/resources/statalist-faq/ * http://www.ats.ucla.edu/stat/stata/