C++ Template Class

 1 #pragma once
2
3 #include "targetver.h"
4
5 #include <stdio.h>
6 #include <tchar.h>
7
8 template <class T>
9 class CThree
10 {
11 public:
12 CThree(T t1,T t2,T t3);
13 T Min();
14 T Max();
15 private:
16 T a,b ,c;
17 };

  


 1 #include "stdafx.h"
2 #include <ostream>
3 //#include <iostream>
4 using namespace std;
5
6 template <class T>
7 T CThree<T>::Min()
8 {
9 T minab=a<b?a:b;
10 return minab<c?minab:c;
11 }
12 template <class T>
13 T CThree<T>::Max()
14 {
15 T maxab=a<b?b:a;
16 return maxab<c?c:maxab;
17 }
18 template <class T>
19 CThree<T>::CThree(T t1, T t2, T t3):a(t1),b(t2),c(t3)//?
20 {
21 return;
22 }
23 int _tmain(int argc, _TCHAR* argv[])
24 {
25 CThree<int> obj1(2,5,4);
26 cout<<obj1.Min()<<endl;
27 cout<<obj1.Max()<<endl<<std::max(;
28
29 CThree<float> obj2(8.52f,-6.75f,4.54f);
30 cout <<obj2.Max()<<endl;
31 cout<<obj2.Min()<<endl;
32
33 return 0;
34 }

  

posted @ 2011-09-08 20:39  soderman  阅读(406)  评论(0编辑  收藏  举报