您的位置:首页 > 编程语言 > C语言/C++

尝试提取c++类函数地址(1)

2016-03-10 18:39 423 查看
#include<iostream>
using namespace std;

class A{
public:
void f(){
cout << "ordinary" << endl;
}
static void e(){

cout << "static" << endl;

}
int a;
int b;
static int c;
static const int d = 100;//could assgined
};
int main(){
A p;
int *a = &p.a;
int p1 = (int)a;
cout << "memember:"  << p1 << endl;

int A::*p2 = &A::b;
cout << "memember:"  << p2 << endl;//1

typedef void (A::*pf)();
pf f = &A::f;
cout << "function:" << f << endl; //1
(p.*f)();
typedef void (*pf1)();//
pf1 f1 = &A::e;
cout << "static function:" << (int)f1 << endl;

void (*f3)();//
f3 = A::e;
f3();
cout << "static function:" << (int)f3 << endl;
void (A::*f4)();
f4 = &A::f;
(p.*f4)();
cout << "function:" << f4 << endl;
/*
pf f2 = p.f;
cout << "function:" << f2 << endl;*/
f4 = &p.f;
(p.*f4)();
return 0;
}

C:\Users\jackz\Desktop\codes\cpp>g++ "&ClassPointer.cpp"

C:\Users\jackz\Desktop\codes\cpp>a
memember:2686692
memember:1
function:1
ordinary
static function:4425512
static
static function:4425512
ordinary
function:1
ordinary
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: