使用 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/