C ++重载方法指针 [英] C++ overloaded method pointer
本文介绍了C ++重载方法指针的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何获取方法指针指向某个方法的特定重载:
How do I get a method pointer to a particular overload of a method:
struct A {
void f();
void f(int);
void g();
};
我知道
&A::g
是指向 g
。但是如何获得 f
或 f(int)
?
is a pointer to g
. But how do I get a pointer to f
or f(int)
?
推荐答案
(void (A::*)()) &A::f
(void (A::*)(int)) &A::f
函数指针和成员函数指针
function pointers and member function pointers have this feature - the overload can be resolved by to what the result was assigned or cast.
如果函数是静态的,你应该把它们当作普通函数来处理:
If the functions are static, then you should treat them as ordinary functions:
(void (*)()) &A::f;
(void (*)(int)) &A::f;
或甚至
(void (*)()) A::f;
(void (*)(int)) A::f;
这篇关于C ++重载方法指针的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文