获取函数成员地址 [英] get function member address
本文介绍了获取函数成员地址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法获得函数成员的确切地址?
例如我有:
Is there any way to get the exact address of a function member? For example I have :
struct foo
{
void print() { printf("bla bla bla"); }
};
//////////////////////////////////////////////////////////////
unsigned int address = foo::print;
推荐答案
您可以使用以下语法声明指针成员函数:
You can use the following syntax to declare the pointer to the member function:
typedef void (foo::*address)();
address func = &foo::print;
为了调用非静态成员函数,您将需要该类的现有实例:
In order to call non-static member function you will need an existing instance of that class:
(fooInstance.*func)();
这篇关于获取函数成员地址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文