64,642
社区成员
发帖
与我相关
我的任务
分享
#include <iostream>
using namespace std;
class A
{
int a;
public:
typedef void (A::* PF)();
static PF GetFoo(){return &A::foo;}
private:
void foo()
{
cout << this << endl;
cout << "A::foo()" << endl;
}
};
int main()
{
(((A*)0)->*A::GetFoo())();
return 0;
}
class A
{
public:
void fun()
{
cout<<"A::fun()\n";
}
void foo()
{
cout<<"A::foo()\n";
}
};
typedef void (A::* PF)();
typedef void (*F)();
int main()
{
char str[64];
PF pf1=&A::fun;
PF pf2=&A::foo;
sprintf(str,"%p\t%p",pf1,pf2);
printf("%s\n",str);
long a,b;
sscanf(str,"%x%x",&a,&b);
cout<<a<<'\t'<<b<<'\n';
F f1=(F)a;
F f2=(F)b;
f1();
f2();
return 0;
}
struct test
{
int mx;
public:
test(int x):mx(x)
{
}
int __stdcall print()
{
return printf("%d\n",mx);
}
};
int(__stdcall *F)(test*);
int main()
{
test * p = new test(10);
F pf = (F)&test::print;
pf( p );
return 0;
}
struct test
{
int mx;
public:
test(int x):mx(x)
{
}
int stdcall print()
{
return printf("%d\n",mx);
}
};
int(*F)(test*);
int main()
{
test * p = new test(10);
F *pf = (F*)&test::print;
pf( p );
return 0;
}