| 1 | //
|
|---|
| 2 | // Copyright (c) 2015 Zenterio AB
|
|---|
| 3 | //
|
|---|
| 4 | #include <stdio.h>
|
|---|
| 5 | #include <boost/function.hpp>
|
|---|
| 6 | #include <boost/bind.hpp>
|
|---|
| 7 |
|
|---|
| 8 | #define DO_CRASH
|
|---|
| 9 |
|
|---|
| 10 | #include <string>
|
|---|
| 11 |
|
|---|
| 12 | class Test
|
|---|
| 13 | {
|
|---|
| 14 | public:
|
|---|
| 15 | Test(boost::function<void()> a_Function) : m_Function(a_Function)
|
|---|
| 16 | {
|
|---|
| 17 | // Empty
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | void F()
|
|---|
| 21 | {
|
|---|
| 22 | m_Function();
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | private:
|
|---|
| 26 | boost::function<void()> m_Function;
|
|---|
| 27 | };
|
|---|
| 28 |
|
|---|
| 29 | void Fn(int val)
|
|---|
| 30 | {
|
|---|
| 31 | printf("val=%d\r\n", val);
|
|---|
| 32 | }
|
|---|
| 33 |
|
|---|
| 34 | void DoTest()
|
|---|
| 35 | {
|
|---|
| 36 | printf("1\r\n");
|
|---|
| 37 | boost::function<void()> f = boost::bind(Fn, 100);
|
|---|
| 38 | Test test(f);
|
|---|
| 39 | #ifndef DO_CRASH
|
|---|
| 40 | printf("2\r\n"); // printf of life!
|
|---|
| 41 | #endif
|
|---|
| 42 | test.F();
|
|---|
| 43 | printf("3\r\n");
|
|---|
| 44 | }
|
|---|
| 45 |
|
|---|
| 46 | int main(int argc, char** argv)
|
|---|
| 47 | {
|
|---|
| 48 | DoTest();
|
|---|
| 49 | return 0;
|
|---|
| 50 | }
|
|---|