Код: Выделить всё
class myA {
public:
MyA() = default;
void func(int) { ... };
};
class myB {
public:
MyB() = default;
void func2(int) { ... };
};
auto myA = std::make_shared_ptr();
auto myB = std::make_shared_ptr();
run(myA, &myA::func, 1, 5);
run(myB, &myB::func2, 1, 3);
Код: Выделить всё
template
void run(std::shared_ptr c, F f, int a, int b)
{
std::thread([&c, &f, a, b]() {
while (true) {
// I know this is wrong, but how to call the
// functions passed in (F).
c.f(a);
std::this_thread::sleep_for(std::chrono::seconds(b));
}
}).detach();
}
Подробнее здесь: https://stackoverflow.com/questions/793 ... e-function
Мобильная версия