72.函数模板指针与类函数模板的绑定

 1 #include <iostream>
 2 #include <functional>
 3 using namespace std;
 4 using namespace std::placeholders;
 5 
 6 template <typename T>
 7 void show(T t)
 8 {
 9     cout << t << endl;
10 }
11 
12 class MyClass
13 {
14 public:
15     template <class T>
16     void show(T t)
17     {
18         cout << t << endl;
19     }
20     void run()
21     {
22         show(123);
23     }
24 };
25 
26 void main()
27 {
28     //函数模板指针
29     /*void(*p)(int i) = show<int>;
30     p(10);*/
31     //调用类函数模板
32     /*MyClass my;
33     my.show(1234);*/
34     MyClass my;
35     auto fun = bind(&MyClass::show<int>, &my, _1);
36     fun(12);
37     system("pause");
38 }

 

posted @ 2018-03-15 16:41  喵小喵~  阅读(203)  评论(0)    收藏  举报