类模板
1 /* 类模板 */
2
3 #include<iostream>
4 #include<string>
5
6 using namespace std;
7
8 template <class T>
9 class com
10 {
11 private:
12 T a;
13 T b;
14 public:
15 com(T a,T b):a(a),b(b)
16 {
17
18 }
19 T add()
20 {
21 cout << a+b << endl;
22 return a+b;
23 }
24 };
25
26
27
28 void main()
29 {
30 com<int> com1(10,19);
31 com1.add();
32
33 com<double> com2(12.3,13.99);
34 com2.add();
35
36
37 string str1 = "ABC";
38 string str2 = "XYZ";
39 com<string> com3(str1,str2);
40 com3.add();
41
42 cin.get();
43 }
长风破浪会有时,直挂云帆济沧海
posted on 2015-06-10 22:39 Dragon-wuxl 阅读(96) 评论(0) 收藏 举报
浙公网安备 33010602011771号