类模板

#include <bits/stdc++.h>
using namespace std;
#define SPO(n) fixed << setprecision(n)
#define endl '\n'
#define ifor(i, l, r) for (long long(i) = (l); (i) <= (r); ++(i))
#define rfor(i, r, l) for (long long(i) = (r); (i) >= (l); --(i))
typedef long long ll;
const int IINF = 0x3f3f3f3f;
const long long LINF = 0x3f3f3f3f3f3f3f3f;
const double EPS = 1.0e-9;
const long long MOD = 1e9 + 7;
const long long MAX = 1e5 + 5;

template <class numtype>
class com {
		numtype c1;
		numtype c2;
	public:
		com(numtype x, numtype y);
		numtype max();
};
template <class numtype>
numtype com<numtype>::max() {
	return c1>c2?c1:c2;

}
template <class numtype>//类外定义构造函数,成员函数需要使用函数模板
com<numtype>::com(numtype x,numtype y) {
	c1=x;
	c2=y;
}
int main() {
	std::ios::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	com<int> a1(45,56);
	com<double>a2(56.230,461.2630);;
	cout<<a2.max();
	return 0;
}
全部评论

相关推荐

风流倜傥从哥:这个项目确实太简单了有点,做点大项目。。。
点赞 评论 收藏
分享
01-08 09:40
中南大学 Java
苏苏加油努力:你的女神不回你消息,并且给别的男生发消息 be like
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客企业服务