64,654
社区成员
发帖
与我相关
我的任务
分享
class CTest
{
public:
static int callback(CTest * pThis)
{
std::cout<<"run"<<std::endl;
return 0;
}
};
typedef int (CTest::*FUNC)(CTest *);
int main()
{
CTest a;
FUNC fp=CTest::callback;
(a.*fp)(&a);
return 0;
}
class CTest
{
public:
int another()
{
//
return 0;
}
static int callback(CTest * pThis)
{
//std::cout<<"run"<<std::endl;
return 0;
}
};
int main()
{
CTest a;
//non-member functon version
int (*cb)(CTest*) = &CTest::callback;
(*cb)(&a);
//member fuction version
int (CTest::*cb2)() = &CTest::another;
(a.*cb2)();
return 0;
}
#include <iostream>
using namespace std;
class CTest
{
public:
static int callback(CTest * pThis)
{
std::cout<<"run"<<std::endl;
return 0;
}
};
typedef int (*FUNC)(CTest *);
int main()
{
CTest a;
FUNC fp=&CTest::callback;
fp(&a);
return 0;
}
class CTest
{
public:
static int callback(CTest * pThis)
{
std::cout<<"run"<<std::endl;
return 0;
}
int callback2(){ callback(this); }
};
typedef int (CTest::*FUNC)();
typedef int (*FUNC2)(CTest *);
int main()
{
CTest a;
FUNC fp= &CTest::callback2;
FUNC2 fp2= CTest::callback;
(a.*fp)();
fp2(&a);
return 0;
}