前面两篇文章我相信大家反复读了之后对这节不陌生了:
首先来看代码:
class Demo
{
public://静态成员变量static const int sx = 0;//静态函数static void SF1()
{}
public://成员变量int x;
public://成员函数void F1()
{cout << "I'm from Demo::F1()" << endl;}void F2()
{cout << "I'm from Demo::F1()" << endl;}virtual void F3()
{cout << "virtual F3()" << endl;}
public://构造函数,C++语法不允许获取构造函数和析构函数地址,要分析其地址,只能查看生产的汇编代码了。Demo(){}//析构函数~Demo(){}
};
typedef void (Demo::*Func)();
typedef void(*func)();
union
{Func f;void *addr;
}ut;int main(int argc, char** argv)
{int i = 0;cout << "main()函数的地址是 :" << std::hex << std::showbase << main << endl;ut.f = &Demo::F1;cout << "成员函数F1()的地址是 :"