我有一个全局的普通函数指针 ,
我想让他指到一个类中的成员函数(非静态,函数内可使用this指针)该函数指针会在一个静态成员函数中被调用,我应该如何给那个函数指针赋值呀

解决方案 »

  1.   

    如果没有this指针,即使知道成员函数地址也是没用啊。
      

  2.   

    lz的意思好象是想在一个静态成员函数中调用非静态成员函数,这是C++不允许的。
      

  3.   

    class test
    {public:
      static int invoke(test* p )
      {
        return p->func(); 
      }
    private:
       int func();
    };int main()
    {
      test x;
      test::invoke( &x );
    }
      

  4.   


    static fun(LPVOID* lpParam)
    {
      CYourClass* pClass = (CYourClass*)lpParam;
      pClass->YourFunc();
    }
    CYourClass yClass;
    fun(&yClass);
      

  5.   

    找到一段代码#include "stdafx.h"
    #include <iostream.h>class X{
    public:
        void foo(int b,int c){
            this->a=b*c;
            
        }
        int a;
    };int main(){
        void (X::*pXfoo)(int,int);
        void (__stdcall*pfoo)(int,int);
        //协调调用约定 让被调函数进行栈的清理
        
        pXfoo = X::foo;
        __asm{
            push eax
            mov eax,dword ptr pXfoo
            mov dword ptr pfoo,eax
            pop  eax
            //pfoo = pXfoo
        }
        X x;    //使用对象地址给this指针赋值
        __asm push ecx
        __asm lea ecx,x
        pfoo(3,4);
        __asm pop ecx
    cout<<x.a<<endl;
        //另一种类似__thiscall调用约定的是__fastcall
        //但是使用__fastcall,则所有参数将被放入寄存器,则成员函数产生异常
    }
    这个代码在程序下可以,
    我想问如果用在dll当中,不是还要进行什么换算?