我是编程器的新手,我必须为API创建一个使用函数作为参数的方法.所以,在我的标题中,我已经完成了:
typedef void(*target_function)(std::string client_ip);
void my_method(std::string path_name, std::function<target_function> a_function);
Run Code Online (Sandbox Code Playgroud)
在我的cpp中,我尝试过这种方式:
void my_class:: my_method(std::string path_name, std::function<target_function> )
{
///
}
Run Code Online (Sandbox Code Playgroud)
但它不会编译.
我对此非常困惑......你能帮助我吗?
编辑:它炒!谢谢,大家,非常快速的回答!
@ Cheers-and-hth-alf是对的.但我更喜欢这个:
typedef std::function<void (std::string)> TTargetFunc;
void my_method(std::string path_name, TTargetFunc a_function);
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
524 次 |
| 最近记录: |