#include <iostream>
#include <string>
using namespace std;
template<class T>
T MaxNum(T x,T y)
{
return (x > y ? x : y);
}
template <class CC>
class CMaxNum{
public:
CC m_x,m_y;
CMaxNum(CC x,CC y)
{
m_x = x;
m_y = y;
}
CC GetMaxNum()
{
return (m_x > m_y ? m_x : m_y);
}
};
int _tmain(void)
{
int nMax = MaxNum(10,12);
cout<<nMax<<endl;
float fMax = MaxNum(10.0f,55.2f);
cout<<fMax<<endl;
double dMax = MaxNum(10.10f,12.11f);
cout<<dMax<<endl;
CMaxNum<int>nMyMax(20,30);
int ret = nMyMax.GetMaxNum();
cout<<ret<<endl;
return 0;
}
简单的C++ template实例
最新推荐文章于 2024-06-04 10:54:26 发布