そのようなコードを検討してください:
class MyClass{
public:
void MyFunc(int x){
std::cout << x << std::endl;
}
};
int main(){
MyClass* class_ptr = new MyClass();
void (Myclass::*member_func_ptr)(int) = &MyClass::MyFunc;
// This should output '5'.
(class_ptr->*member_func_ptr)(5);
/* ??? */
// I want the following to output '5' exactly the same way as previous call.
func_ptr(5);
}
func_ptr(...)から MyFuncを呼び出すには、このコードをどのように完成させる必要があり*class_ptrますか?
可能であれば、何らかの形で aと aを a に結合しMyClass*void (Myclass::*)(int)void (*)(int)たいと考えています。
std::mem_fnそうでない場合は、 and std::function(または他の機能的なユーティリティ)を巧妙に使用することでうまくいくと思います。
理想的には、C++11 ソリューションが必要です (egstd::mem_funは非推奨になっているため)。