Тостер
- 1 ответ
- 0 вопросов
12
Вклад в тег
#include <iostream>
#include <functional>
using namespace std;
class MyClass {
public:
void hello() {
cout << "Hello from " << __LINE__ << endl;
}
};
static void hello() {
cout << "Hello from " << __LINE__ << endl;
}
static void do_with_callback( std::function<void()> && callback ) {
callback();
}
int main() {
MyClass cl;
do_with_callback( std::function<void()>(hello) ); // VC 2012 fix
do_with_callback( std::bind(&MyClass::hello, &cl) );
do_with_callback( [&](){
cl.hello();
} );
return 0;
}
Hello from 15
Hello from 9
Hello from 9