What is already there:

#include <functional> #include <Windows.h> #include <iostream> #include <agents.h> #include <ppltasks.h> template <class T> void call_after(T& callback, unsigned int timeInMs) { concurrency::task_completion_event<void> tce; auto call = new concurrency::call<int>( [callback, tce](int) { callback(); tce.set(); }); auto timer = new concurrency::timer<int>(timeInMs, 0, call, false); concurrency::task<void> event_set(tce); event_set.then([timer, call]() { delete call; delete timer; }); timer->start(); } 

That does not work:

 std::function<void()> callback = this->Disconnect; // тут ошибка, C3867 (в вызове функции отсутствует список аргументов) call_after(callback, 5000); 

The this->Disconnect() method is a non-static class method that has a void return type and takes no arguments.

Question: how to solve this problem? How on the timer, through an interval of time to cause a method which is a nonstatic member of a class?

    1 answer 1

    Some such options:

     std::function<void()> callback1 = std::bind(&Foo::Disconnect, this); std::function<void()> callback2 = [this](){this->Disconnect();}; 

    By writing this->Disconnect , you do not take an object of type std::function , but call a function without arguments.

    • Thanks, the first option with bind came up, the second option is not working, the compiler swears at a syntax error. - Alexis
    • 2
      There was a typo. I confused the order of empty brackets. Be careful. - user1056837 2:49 pm