Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <functional>
- #include <exception>
- using namespace std;
- class Foo {
- public:
- virtual void print() = 0;
- };
- class Bar : public Foo {
- public:
- void print() {
- std::cout << "I'm bar!\n";
- }
- };
- template <typename T>
- std::function<void(Foo*)> make_wrapper(std::function<void(T)> fct) {
- return [fct](Foo* event) {
- T* x = dynamic_cast<T*>(event);
- fct(*x);
- };
- }
- int main(void) {
- Bar x = Bar();
- Foo* y = &x;
- make_wrapper<Bar>([](Bar z){z.print();})(y);
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement