Code
#include <iostream>
#include <windows.h>
using namespace std;
template<class T>
class A
{
public:
A();
A(T _a, T _b);
T sum();
private:
T a;
T b;
};
template <class T>
A<T>::A()
{
a=0;b=0;
}
template<class T>
A<T>::A(T _a,T _b)
{
a=_a;
b=_b;
}
template<class T>
T A<T>::sum()
{
return (a+b);
}
template<class T>
T Min(T x, T y)
{
return(x<y)?x:y;
}
int main()
{
A<int> ai(3,4);
A<double> ad(3.1,4.0);
cout<<ai.sum()<<" "<<ad.sum()<<endl; // 测试摸板类
cout<<"min = " <<min(2, 3)<<endl;
cout<<"min = " <<min(2.3, 3.2)<<endl; // 测试摸板函数
return 0;
}
#include <iostream>
#include <windows.h>
using namespace std;
template<class T>
class A
{
public:
A();
A(T _a, T _b);
T sum();
private:
T a;
T b;
};
template <class T>
A<T>::A()
{
a=0;b=0;
}
template<class T>
A<T>::A(T _a,T _b)
{
a=_a;
b=_b;
}
template<class T>
T A<T>::sum()
{
return (a+b);
}
template<class T>
T Min(T x, T y)
{
return(x<y)?x:y;
}
int main()
{
A<int> ai(3,4);
A<double> ad(3.1,4.0);
cout<<ai.sum()<<" "<<ad.sum()<<endl; // 测试摸板类
cout<<"min = " <<min(2, 3)<<endl;
cout<<"min = " <<min(2.3, 3.2)<<endl; // 测试摸板函数
return 0;
}
VC6.0 调试