如果有该如何使用?

解决方案 »

  1.   

    你到底是什么意思。
    在C++里面都不讲方法的,只讲函数。
    方法是java的
      

  2.   

    方法是什么?
    知道C++有函数指针
    void CRunDllDlg::OnOK() 
    {
    HINSTANCE hinstLib;
    //typedef VOID (*MYPROC)(LPTSTR); 
    typedef VOID (*MYPROC)(CString);
    MYPROC ProcAdd;  CString str_Path = "" , str_Temp = "";
    char ch_Path[1024] = { 0 };
    CFileFind m_File;
    int n_Times = 0; GetModuleFileName( NULL , ch_Path , 256 );
    str_Path = ch_Path; str_Temp = str_Path.Left( str_Path.GetLength() - 10 );
    str_Path = str_Temp;
    str_Path = str_Path + "Xagent.dll"; BOOL bWorking = m_File.FindFile( str_Path );
    while( bWorking ){
    bWorking = m_File.FindNextFile();
    if ( m_File.IsDots() )
    continue;
    if ( m_File.IsDirectory() )
    continue;
    n_Times ++;
    }
    if( n_Times != 1 ){
    MessageBox( "对不起!您没有购买该模块。" );
    return;
    } //从这里开始调用Dll,以上部分是查看Dll是否存在
    hinstLib = LoadLibrary("Xagent.dll");  if (hinstLib == NULL){
    MessageBox( "调用Xagent.dll出错。" );
    FreeLibrary(hinstLib);
    return;
    }else{
    ProcAdd = (MYPROC) GetProcAddress(hinstLib, "SetServerIP");
    if( ProcAdd == NULL ){
    MessageBox( "调用函数出错SetServerIP。" );
    FreeLibrary(hinstLib);
    return;
    }else{
    ProcAdd( "192.168.0.123" );
    }
    }
    FreeLibrary(hinstLib);
    //CDialog::OnOK();
    }
      

  3.   

    typedef int(*FUNC) (int a,int b); //声明FUNC是一个函数指针类型
    FUNC func;  //func为一个有两个整形参数,返回整数的函数指针。
      

  4.   

    class CMySocket  
    {
    public:
       void get();
    };
    CMySocket::get()
    {
      
    }如何得到get()函数的指针?
      

  5.   

    大概是这样的吧:具体记不得了
    CMySocket::*p = CMySocket::get()====
      

  6.   

    谢谢robothn(雷鸟)的回答,可是不对...
      

  7.   

    #include "stdafx.h"
    #include <iostream>
    using namespace std;class A
    {
    public:
    void Display()
    {
    cout << "Hello world!" << endl;
    }
    };int main(int argc, char* argv[])
    {
    void (A::*p)() = A::Display;
    A a;
    (a.*p)();
    return 0;
    }
    这样使用
      

  8.   

    类的非静态成员函数都有隐含的this指针,当然不能直接用指针去访问。否则你岂不是可以从外面访问类的私有部分了!
    你要用指针,必须用类的静态函数。
      

  9.   

    xkak2(乾坤一掷)兄说的也对。我也想不通。请liu_feng_fly(笑看风云 搏击苍穹 衔日月) 出来讲讲原因啊
      

  10.   

    A a;
    (a.*p)();
    我是这样调用的,通过一个类的实例a调用,当然就有this指针了。也可以通过指针,比如
    A* pA = new A;
    (pA->*p)();
    这样就可以通过一个类的指针,在搭配一个指向类的成员函数的指针进行使用了。总之,必须先有一个类的实例,然后才能使用指向类的成员函数的指针。
      

  11.   

    对于一个智能指针(smart point),应该重载operator ->*,原因也就在这里