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 CThree10 {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 }

原文链接: https://www.cnblogs.com/sosoman/archive/2011/09/08/2171795.html

欢迎关注

微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍

原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/31946

非原创文章文中已经注明原地址,如有侵权,联系删除

关注公众号【高性能架构探索】,第一时间获取最新文章

转载文章受原作者版权保护。转载请注明原作者出处!

(0)
上一篇 2023年2月8日 上午9:14
下一篇 2023年2月8日 上午9:14

相关推荐