c++类方法回调类似于std::thread

标签 c++ callback

使用 std::thread,您可以传递一个类方法作为要调用的函数。

语法:

std::thread myThread(&MyClass::handler, this);

1.我模仿此行为以允许将类方法传递到我自己的回调例程的函数的语法是什么?

2.如何将此引用存储在变量中?

例如:

Myclass temp;
myfunction(&Myclass::somefunc,temp);

那么呢?

typedef void(*mycallbacktype)(const std::string& someperamiter);
void myfunction(???)

最佳答案

1.What is the syntax of my function to imitate this behavior to allow for passing of class methods to my own callback routines?

它被称为“指向成员的指针”。参见 What are the Pointer-to-Member ->* and .* Operators in C++? 你的第二个问题应该是这样回答的。

关于c++类方法回调类似于std::thread,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46307702/

相关文章:

javascript - 未调用地理编码回调

c++ - 避免资源冲突

c++ - 在 SDL 2.0 中创建 1x1 纹理

c++ - 模板内的编辑列表不保存

c++ - 分配内存时内存使用量不会增加

node.js - 如何优化 Promise 以避免回调/Promise hell

c++ - 回调函数混淆参数?

c# - 与使用 winPcap 代替套接字相关的风险

cocoa - 核心动画回调

r - 如何指定 by( ) 或相关的 apply( ) 函数中使用的 FUN