   A pointer to method in C++
  How do you write a pointer to method in C++? 
  I assume by method you mean class member function.class A {  public:    void func(void);};typedef void (A::*pfn)(void);pfn a_func = &A::func; ;  Or for non-member functions int func(){return 0;}int (*pfunc)() = func; [edited by - Jingo on February 4, 2004 5:03:02 AM];  I have the follwoing code:class A {private:static void InitialScale ();static void (ImageScaler::*pInitialScale)();};voidA::InitialScale (){A:InitialScale();}It says on the last line that the expression does not evaluate to a function, why is that? ;  Because a member function pointer isn't a function. In order to use a member function pointer you need to bind it to an object somehow.void A::InitialScale() {  // create an ImageScaler on the stack, bind it to pInitialScale  //   and call  ImageScaler is;  (is.*A::pInitialScale)();  // create an ImageScaler on the heap, bind it to pInitialScale  //   and call  ImageScaler * p_is = new ImageScaler;  (p_is->*A::pInitialScale)();   delete p_is;}   edit: !@$@ Smiley code   [edited by - SiCrane on February 4, 2004 5:23:24 AM];quote:Original post by SiCrane  Because a member function pointer isn''t a function. In order to use a member function pointer you need to bind it to an object somehow.void A::InitialScale() {  // create an ImageScaler on the stack, bind it to pInitialScale  //   and call  ImageScaler is;  (is.*A::pInitialScale)();  // create an ImageScaler on the heap, bind it to pInitialScale  //   and call  ImageScaler * p_is = new ImageScaler;  (p_is->*A::pInitialScale)();   delete p_is;}    edit: !@$@ Smiley code   [edited by - SiCrane on February 4, 2004 5:23:24 AM]This code doesnt work;  Compiles fine under MSVC .NET 2003. ;  the usual function-pointer.org response   [edited by - petewood on February 4, 2004 5:58:33 AM];  I have the code:voidImageScaler::InitialScale (){ImageScaler is;(is.*ImageScaler:InitialScale)();}and get the following link errors:error LNK2001: unresolved external symbol "private: static void (__thiscall ImageScaler::* ImageScaler:InitialScale)(void)" (?pInitialScale@ImageScaler@@0P81@AEXXZQ1@)Debug/V0P01.exe : fatal error LNK1120: 1 unresolved externals ;  any static member of a class needs to also be defined in a seperate cpp filevoid (ImageScaler::*pInitialScale)() = 0;haven't checked the syntaxedit: using typedefs when you're dealing with pointers to functions can make things a lot easier to read.egint functionTakingDoubleAndString(double, string);typedef int(*FunctionPtr)(double, string);FunctionPtr p = functionTakingDoubleAndString;int result = p(10.5, "hello");   [edited by - petewood on February 4, 2004 7:03:08 AM]