01 #include <iostream>
02
03 using namespace std;
04
05 class Unkown
06 {
07 public:
08 void QueryInterface(int a)
09 {
10 cout<<"Hello, this your world!" <<endl;
11 }
12 };
13
14 template <typename T> class Helper
15 {
16 public:
17 T *t;
18
19 public:
20 T *operator -> ()
21 {
22 cout<<"your world!" <<endl;
23 return t;
24 }
25 };
26
27 int main(int argc, char *argv[])
28 {
29 Helper<Unkown> tt;
30 tt->QueryInterface(10);
31
32 return 0;
33 }
1
view source
print?
01 //函數模板
02 #include <iostream>
03
04 using namespace std;
05
06 template <typename T>
07
08 inline const T &Maximnum(const T &x, const T &y)
09 {
10 if (y > x)
11 {
12 return y;
13 }
14 else
15 {
16 return x;
17 }
18 }
19
20 int main(int argc, char *argv[])
21 {
22 cout<<Maximnum<int>(3, 7) <<endl;
23 cout<<Maximnum(3, 7) <<endl;
24 cout<<Maximnum<double>(3.0, 7.0) <<endl;
25
26 return 0;
27 }
作者:芸渝